mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-22 00:21:55 +00:00
48 lines
969 B
Go
48 lines
969 B
Go
|
package goscrobble
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
type Genre struct {
|
||
|
UUID string `json:"uuid"`
|
||
|
Name string `json:"name"`
|
||
|
}
|
||
|
|
||
|
func getGenre(uuid string) Genre {
|
||
|
var genre Genre
|
||
|
err := db.QueryRow(
|
||
|
"SELECT BIN_TO_UUID(`uuid`, true), `name` FROM `artists` WHERE `uuid` = UUID_TO_BIN(?,true)",
|
||
|
uuid).Scan(&genre.UUID, &genre.Name)
|
||
|
|
||
|
if err != nil {
|
||
|
if err != sql.ErrNoRows {
|
||
|
log.Printf("Error fetching artists: %+v", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return genre
|
||
|
}
|
||
|
|
||
|
func getGenreByName(name string) Genre {
|
||
|
var genre Genre
|
||
|
err := db.QueryRow(
|
||
|
"SELECT BIN_TO_UUID(`uuid`, true), `name` FROM `artists` WHERE `name` = ?",
|
||
|
name).Scan(&genre.UUID, &genre.Name)
|
||
|
|
||
|
if err != nil {
|
||
|
if err != sql.ErrNoRows {
|
||
|
log.Printf("Error fetching artists: %+v", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return genre
|
||
|
}
|
||
|
|
||
|
func (genre *Genre) updateGenreName(name string, value string) error {
|
||
|
_, err := db.Exec("UPDATE `genres` SET `name` = ? WHERE uuid = UUID_TO_BIN(?, true)", name, genre.UUID)
|
||
|
|
||
|
return err
|
||
|
}
|