v1.0.1 заготовка Sea

main v1.0.1
parent 0c09f56c08
commit 60128ac058

@ -1,30 +1,45 @@
package sea
import (
"fmt"
// "fmt"
_ "github.com/go-sql-driver/mysql" // для связи с mysql
"github.com/jmoiron/sqlx"
)
// ============= SEA ============
type Sea struct {
db *sqlx.DB
}
func Connect() (*Sea, error) {
db, err := openDB()
if err != nil {
return nil, err
}
sea := Sea{db: db}
return &sea, nil
}
// ============= ALBUM ============
type Album struct {
Seria string
Cnt int
Hash string
}
func getAlbums(db *sqlx.DB) []Album {
cmd := "call getAlbums()"
var albums []Album
err := db.Select(&albums, cmd)
checkError("get albums", err)
return albums
}
// func getAlbums(db *sqlx.DB) []Album {
// cmd := "call getAlbums()"
// var albums []Album
// err := db.Select(&albums, cmd)
// return albums
// }
func openDB() *sqlx.DB {
fmt.Printf("открываю БД sea\n")
func openDB() (*sqlx.DB, error) {
db, err := sqlx.Open("mysql", "itman:X753951x@(xigmanas:3306)/sea")
checkError("open db", err)
return db
if err != nil {
return nil, err
}
return db, nil
}

Loading…
Cancel
Save