You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package sea
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
// "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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func openDB() (*sqlx.DB, error) {
|
|
|
|
|
db, err := sqlx.Open("mysql", "itman:X753951x@(xigmanas:3306)/sea")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return db, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============= ALBUM ============
|
|
|
|
|
|
|
|
|
|
type Album struct {
|
|
|
|
|
Seria string
|
|
|
|
|
Cnt int
|
|
|
|
|
Hash string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Sea) Albums() ([]Album, error) {
|
|
|
|
|
cmd := "call getAlbums()"
|
|
|
|
|
var albums []Album
|
|
|
|
|
err := s.db.Select(&albums, cmd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return albums, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|