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