2021-04-03 08:29:31 +00:00
|
|
|
package goscrobble
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Genre struct {
|
|
|
|
UUID string `json:"uuid"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:54:53 +00:00
|
|
|
func getGenreByUUID(uuid string) Genre {
|
2021-04-03 08:29:31 +00:00
|
|
|
var genre Genre
|
|
|
|
err := db.QueryRow(
|
2022-01-05 07:58:05 +00:00
|
|
|
`SELECT uuid, name FROM artists WHERE uuid = $1`,
|
2021-04-03 08:29:31 +00:00
|
|
|
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(
|
2022-01-05 07:58:05 +00:00
|
|
|
`SELECT uuid, name FROM artists WHERE name = $1`,
|
2021-04-03 08:29:31 +00:00
|
|
|
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 {
|
2022-01-05 07:58:05 +00:00
|
|
|
_, err := db.Exec(`UPDATE genres SET name = $1 WHERE uuid = $2`, name, genre.UUID)
|
2021-04-03 08:29:31 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|