feat: Rename game to soundtrack throughout codebase
- Database migration: rename game table to soundtrack - Rename game_name to soundtrack_name, game_id to soundtrack_id - Update all SQL queries in soundtrack.sql, song.sql, song_list.sql, statistics.sql - Regenerate sqlc code (soundtrack.sql.go, song.sql.go, etc.) - Update backend: music.go, sync.go, statistics.go - Update server: musicHandler.go, syncHandler.go, routes.go - Update frontend: hello.go - Keep URL paths as /games for backward compatibility Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -1,246 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: game.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const addGamePlayed = `-- name: AddGamePlayed :exec
|
||||
UPDATE game SET times_played = times_played + 1, last_played = now() WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) AddGamePlayed(ctx context.Context, id int32) error {
|
||||
_, err := q.db.Exec(ctx, addGamePlayed, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearGames = `-- name: ClearGames :exec
|
||||
DELETE FROM game
|
||||
`
|
||||
|
||||
func (q *Queries) ClearGames(ctx context.Context) error {
|
||||
_, err := q.db.Exec(ctx, clearGames)
|
||||
return err
|
||||
}
|
||||
|
||||
const findAllGames = `-- name: FindAllGames :many
|
||||
SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash
|
||||
FROM game
|
||||
WHERE deleted IS NULL
|
||||
ORDER BY game_name
|
||||
`
|
||||
|
||||
func (q *Queries) FindAllGames(ctx context.Context) ([]Game, error) {
|
||||
rows, err := q.db.Query(ctx, findAllGames)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Game
|
||||
for rows.Next() {
|
||||
var i Game
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.GameName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAllGamesIncludingDeleted = `-- name: GetAllGamesIncludingDeleted :many
|
||||
SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash
|
||||
FROM game
|
||||
ORDER BY game_name
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllGamesIncludingDeleted(ctx context.Context) ([]Game, error) {
|
||||
rows, err := q.db.Query(ctx, getAllGamesIncludingDeleted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Game
|
||||
for rows.Next() {
|
||||
var i Game
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.GameName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getGameById = `-- name: GetGameById :one
|
||||
SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash
|
||||
FROM game
|
||||
WHERE id = $1
|
||||
AND deleted IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) GetGameById(ctx context.Context, id int32) (Game, error) {
|
||||
row := q.db.QueryRow(ctx, getGameById, id)
|
||||
var i Game
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.GameName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getGameNameById = `-- name: GetGameNameById :one
|
||||
SELECT game_name FROM game WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetGameNameById(ctx context.Context, id int32) (string, error) {
|
||||
row := q.db.QueryRow(ctx, getGameNameById, id)
|
||||
var game_name string
|
||||
err := row.Scan(&game_name)
|
||||
return game_name, err
|
||||
}
|
||||
|
||||
const getIdByGameName = `-- name: GetIdByGameName :one
|
||||
SELECT id FROM game WHERE game_name = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetIdByGameName(ctx context.Context, gameName string) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, getIdByGameName, gameName)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const insertGame = `-- name: InsertGame :one
|
||||
INSERT INTO game (game_name, path, hash, added) VALUES ($1, $2, $3, now()) returning id
|
||||
`
|
||||
|
||||
type InsertGameParams struct {
|
||||
GameName string `json:"game_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertGame(ctx context.Context, arg InsertGameParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, insertGame, arg.GameName, arg.Path, arg.Hash)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const insertGameWithExistingId = `-- name: InsertGameWithExistingId :exec
|
||||
INSERT INTO game (id, game_name, path, hash, added) VALUES ($1, $2, $3, $4, now())
|
||||
`
|
||||
|
||||
type InsertGameWithExistingIdParams struct {
|
||||
ID int32 `json:"id"`
|
||||
GameName string `json:"game_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertGameWithExistingId(ctx context.Context, arg InsertGameWithExistingIdParams) error {
|
||||
_, err := q.db.Exec(ctx, insertGameWithExistingId,
|
||||
arg.ID,
|
||||
arg.GameName,
|
||||
arg.Path,
|
||||
arg.Hash,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const removeDeletionDate = `-- name: RemoveDeletionDate :exec
|
||||
UPDATE game SET deleted=NULL WHERE id=$1
|
||||
`
|
||||
|
||||
func (q *Queries) RemoveDeletionDate(ctx context.Context, id int32) error {
|
||||
_, err := q.db.Exec(ctx, removeDeletionDate, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const resetGameIdSeq = `-- name: ResetGameIdSeq :one
|
||||
SELECT setval('game_id_seq', (SELECT MAX(id) FROM game)+1)
|
||||
`
|
||||
|
||||
func (q *Queries) ResetGameIdSeq(ctx context.Context) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, resetGameIdSeq)
|
||||
var setval int64
|
||||
err := row.Scan(&setval)
|
||||
return setval, err
|
||||
}
|
||||
|
||||
const setGameDeletionDate = `-- name: SetGameDeletionDate :exec
|
||||
UPDATE game SET deleted=now() WHERE deleted IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SetGameDeletionDate(ctx context.Context) error {
|
||||
_, err := q.db.Exec(ctx, setGameDeletionDate)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateGameHash = `-- name: UpdateGameHash :exec
|
||||
UPDATE game SET hash=$1, last_changed=now() WHERE id=$2
|
||||
`
|
||||
|
||||
type UpdateGameHashParams struct {
|
||||
Hash string `json:"hash"`
|
||||
ID int32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateGameHash(ctx context.Context, arg UpdateGameHashParams) error {
|
||||
_, err := q.db.Exec(ctx, updateGameHash, arg.Hash, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateGameName = `-- name: UpdateGameName :exec
|
||||
UPDATE game SET game_name=$1, path=$2, last_changed=now() WHERE id=$3
|
||||
`
|
||||
|
||||
type UpdateGameNameParams struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
ID int32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateGameName(ctx context.Context, arg UpdateGameNameParams) error {
|
||||
_, err := q.db.Exec(ctx, updateGameName, arg.Name, arg.Path, arg.ID)
|
||||
return err
|
||||
}
|
||||
@@ -10,19 +10,6 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
ID int32 `json:"id"`
|
||||
GameName string `json:"game_name"`
|
||||
Added time.Time `json:"added"`
|
||||
Deleted *time.Time `json:"deleted"`
|
||||
LastChanged *time.Time `json:"last_changed"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
LastPlayed *time.Time `json:"last_played"`
|
||||
NumberOfSongs int32 `json:"number_of_songs"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
Token string `json:"token"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
@@ -33,20 +20,33 @@ type Session struct {
|
||||
}
|
||||
|
||||
type Song struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
Hash string `json:"hash"`
|
||||
FileName *string `json:"file_name"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
Hash string `json:"hash"`
|
||||
FileName *string `json:"file_name"`
|
||||
}
|
||||
|
||||
type SongList struct {
|
||||
MatchDate time.Time `json:"match_date"`
|
||||
MatchID int32 `json:"match_id"`
|
||||
SongNo int32 `json:"song_no"`
|
||||
GameName *string `json:"game_name"`
|
||||
SongName *string `json:"song_name"`
|
||||
MatchDate time.Time `json:"match_date"`
|
||||
MatchID int32 `json:"match_id"`
|
||||
SongNo int32 `json:"song_no"`
|
||||
SoundtrackName *string `json:"soundtrack_name"`
|
||||
SongName *string `json:"song_name"`
|
||||
}
|
||||
|
||||
type Soundtrack struct {
|
||||
ID int32 `json:"id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Added time.Time `json:"added"`
|
||||
Deleted *time.Time `json:"deleted"`
|
||||
LastChanged *time.Time `json:"last_changed"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
LastPlayed *time.Time `json:"last_played"`
|
||||
NumberOfSongs int32 `json:"number_of_songs"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
type Vgmq struct {
|
||||
|
||||
@@ -24,20 +24,20 @@ func (q *Queries) AddHashToSong(ctx context.Context, arg AddHashToSongParams) er
|
||||
}
|
||||
|
||||
const addSong = `-- name: AddSong :exec
|
||||
INSERT INTO song(game_id, song_name, path, file_name, hash) VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO song(soundtrack_id, song_name, path, file_name, hash) VALUES ($1, $2, $3, $4, $5)
|
||||
`
|
||||
|
||||
type AddSongParams struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
FileName *string `json:"file_name"`
|
||||
Hash string `json:"hash"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
FileName *string `json:"file_name"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddSong(ctx context.Context, arg AddSongParams) error {
|
||||
_, err := q.db.Exec(ctx, addSong,
|
||||
arg.GameID,
|
||||
arg.SoundtrackID,
|
||||
arg.SongName,
|
||||
arg.Path,
|
||||
arg.FileName,
|
||||
@@ -48,16 +48,16 @@ func (q *Queries) AddSong(ctx context.Context, arg AddSongParams) error {
|
||||
|
||||
const addSongPlayed = `-- name: AddSongPlayed :exec
|
||||
UPDATE song SET times_played = times_played + 1
|
||||
WHERE game_id = $1 AND song_name = $2
|
||||
WHERE soundtrack_id = $1 AND song_name = $2
|
||||
`
|
||||
|
||||
type AddSongPlayedParams struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
SongName string `json:"song_name"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SongName string `json:"song_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddSongPlayed(ctx context.Context, arg AddSongPlayedParams) error {
|
||||
_, err := q.db.Exec(ctx, addSongPlayed, arg.GameID, arg.SongName)
|
||||
_, err := q.db.Exec(ctx, addSongPlayed, arg.SoundtrackID, arg.SongName)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -92,17 +92,17 @@ func (q *Queries) ClearSongs(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const clearSongsByGameId = `-- name: ClearSongsByGameId :exec
|
||||
DELETE FROM song WHERE game_id = $1
|
||||
const clearSongsBySoundtrackId = `-- name: ClearSongsBySoundtrackId :exec
|
||||
DELETE FROM song WHERE soundtrack_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) ClearSongsByGameId(ctx context.Context, gameID int32) error {
|
||||
_, err := q.db.Exec(ctx, clearSongsByGameId, gameID)
|
||||
func (q *Queries) ClearSongsBySoundtrackId(ctx context.Context, soundtrackID int32) error {
|
||||
_, err := q.db.Exec(ctx, clearSongsBySoundtrackId, soundtrackID)
|
||||
return err
|
||||
}
|
||||
|
||||
const fetchAllSongs = `-- name: FetchAllSongs :many
|
||||
SELECT game_id, song_name, path, times_played, hash, file_name FROM song
|
||||
SELECT soundtrack_id, song_name, path, times_played, hash, file_name FROM song
|
||||
`
|
||||
|
||||
func (q *Queries) FetchAllSongs(ctx context.Context) ([]Song, error) {
|
||||
@@ -115,7 +115,7 @@ func (q *Queries) FetchAllSongs(ctx context.Context) ([]Song, error) {
|
||||
for rows.Next() {
|
||||
var i Song
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.SoundtrackID,
|
||||
&i.SongName,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
@@ -132,14 +132,14 @@ func (q *Queries) FetchAllSongs(ctx context.Context) ([]Song, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const findSongsFromGame = `-- name: FindSongsFromGame :many
|
||||
SELECT game_id, song_name, path, times_played, hash, file_name
|
||||
const findSongsFromSoundtrack = `-- name: FindSongsFromSoundtrack :many
|
||||
SELECT soundtrack_id, song_name, path, times_played, hash, file_name
|
||||
FROM song
|
||||
WHERE game_id = $1
|
||||
WHERE soundtrack_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) FindSongsFromGame(ctx context.Context, gameID int32) ([]Song, error) {
|
||||
rows, err := q.db.Query(ctx, findSongsFromGame, gameID)
|
||||
func (q *Queries) FindSongsFromSoundtrack(ctx context.Context, soundtrackID int32) ([]Song, error) {
|
||||
rows, err := q.db.Query(ctx, findSongsFromSoundtrack, soundtrackID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (q *Queries) FindSongsFromGame(ctx context.Context, gameID int32) ([]Song,
|
||||
for rows.Next() {
|
||||
var i Song
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.SoundtrackID,
|
||||
&i.SongName,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
@@ -166,14 +166,14 @@ func (q *Queries) FindSongsFromGame(ctx context.Context, gameID int32) ([]Song,
|
||||
}
|
||||
|
||||
const getSongWithHash = `-- name: GetSongWithHash :one
|
||||
SELECT game_id, song_name, path, times_played, hash, file_name FROM song WHERE hash = $1
|
||||
SELECT soundtrack_id, song_name, path, times_played, hash, file_name FROM song WHERE hash = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSongWithHash(ctx context.Context, hash string) (Song, error) {
|
||||
row := q.db.QueryRow(ctx, getSongWithHash, hash)
|
||||
var i Song
|
||||
err := row.Scan(
|
||||
&i.GameID,
|
||||
&i.SoundtrackID,
|
||||
&i.SongName,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
const getSongList = `-- name: GetSongList :many
|
||||
SELECT match_date, match_id, song_no, game_name, song_name
|
||||
SELECT match_date, match_id, song_no, soundtrack_name, song_name
|
||||
FROM song_list
|
||||
WHERE match_date = $1
|
||||
ORDER BY song_no DESC
|
||||
@@ -30,7 +30,7 @@ func (q *Queries) GetSongList(ctx context.Context, matchDate time.Time) ([]SongL
|
||||
&i.MatchDate,
|
||||
&i.MatchID,
|
||||
&i.SongNo,
|
||||
&i.GameName,
|
||||
&i.SoundtrackName,
|
||||
&i.SongName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -44,16 +44,16 @@ func (q *Queries) GetSongList(ctx context.Context, matchDate time.Time) ([]SongL
|
||||
}
|
||||
|
||||
const insertSongInList = `-- name: InsertSongInList :exec
|
||||
INSERT INTO song_list (match_date, match_id, song_no, game_name, song_name)
|
||||
INSERT INTO song_list (match_date, match_id, song_no, soundtrack_name, song_name)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
`
|
||||
|
||||
type InsertSongInListParams struct {
|
||||
MatchDate time.Time `json:"match_date"`
|
||||
MatchID int32 `json:"match_id"`
|
||||
SongNo int32 `json:"song_no"`
|
||||
GameName *string `json:"game_name"`
|
||||
SongName *string `json:"song_name"`
|
||||
MatchDate time.Time `json:"match_date"`
|
||||
MatchID int32 `json:"match_id"`
|
||||
SongNo int32 `json:"song_no"`
|
||||
SoundtrackName *string `json:"soundtrack_name"`
|
||||
SongName *string `json:"song_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSongInList(ctx context.Context, arg InsertSongInListParams) error {
|
||||
@@ -61,7 +61,7 @@ func (q *Queries) InsertSongInList(ctx context.Context, arg InsertSongInListPara
|
||||
arg.MatchDate,
|
||||
arg.MatchID,
|
||||
arg.SongNo,
|
||||
arg.GameName,
|
||||
arg.SoundtrackName,
|
||||
arg.SongName,
|
||||
)
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: soundtrack.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const addSoundtrackPlayed = `-- name: AddSoundtrackPlayed :exec
|
||||
UPDATE soundtrack SET times_played = times_played + 1, last_played = now() WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) AddSoundtrackPlayed(ctx context.Context, id int32) error {
|
||||
_, err := q.db.Exec(ctx, addSoundtrackPlayed, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearSoundtracks = `-- name: ClearSoundtracks :exec
|
||||
DELETE FROM soundtrack
|
||||
`
|
||||
|
||||
func (q *Queries) ClearSoundtracks(ctx context.Context) error {
|
||||
_, err := q.db.Exec(ctx, clearSoundtracks)
|
||||
return err
|
||||
}
|
||||
|
||||
const findAllSoundtracks = `-- name: FindAllSoundtracks :many
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash
|
||||
FROM soundtrack
|
||||
WHERE deleted IS NULL
|
||||
ORDER BY soundtrack_name
|
||||
`
|
||||
|
||||
func (q *Queries) FindAllSoundtracks(ctx context.Context) ([]Soundtrack, error) {
|
||||
rows, err := q.db.Query(ctx, findAllSoundtracks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Soundtrack
|
||||
for rows.Next() {
|
||||
var i Soundtrack
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SoundtrackName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAllSoundtracksIncludingDeleted = `-- name: GetAllSoundtracksIncludingDeleted :many
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash
|
||||
FROM soundtrack
|
||||
ORDER BY soundtrack_name
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllSoundtracksIncludingDeleted(ctx context.Context) ([]Soundtrack, error) {
|
||||
rows, err := q.db.Query(ctx, getAllSoundtracksIncludingDeleted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Soundtrack
|
||||
for rows.Next() {
|
||||
var i Soundtrack
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SoundtrackName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getIdBySoundtrackName = `-- name: GetIdBySoundtrackName :one
|
||||
SELECT id FROM soundtrack WHERE soundtrack_name = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetIdBySoundtrackName(ctx context.Context, soundtrackName string) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, getIdBySoundtrackName, soundtrackName)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getSoundtrackById = `-- name: GetSoundtrackById :one
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash
|
||||
FROM soundtrack
|
||||
WHERE id = $1
|
||||
AND deleted IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) GetSoundtrackById(ctx context.Context, id int32) (Soundtrack, error) {
|
||||
row := q.db.QueryRow(ctx, getSoundtrackById, id)
|
||||
var i Soundtrack
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SoundtrackName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSoundtrackNameById = `-- name: GetSoundtrackNameById :one
|
||||
SELECT soundtrack_name FROM soundtrack WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSoundtrackNameById(ctx context.Context, id int32) (string, error) {
|
||||
row := q.db.QueryRow(ctx, getSoundtrackNameById, id)
|
||||
var soundtrack_name string
|
||||
err := row.Scan(&soundtrack_name)
|
||||
return soundtrack_name, err
|
||||
}
|
||||
|
||||
const insertSoundtrack = `-- name: InsertSoundtrack :one
|
||||
INSERT INTO soundtrack (soundtrack_name, path, hash, added) VALUES ($1, $2, $3, now()) returning id
|
||||
`
|
||||
|
||||
type InsertSoundtrackParams struct {
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSoundtrack(ctx context.Context, arg InsertSoundtrackParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, insertSoundtrack, arg.SoundtrackName, arg.Path, arg.Hash)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const insertSoundtrackWithExistingId = `-- name: InsertSoundtrackWithExistingId :exec
|
||||
INSERT INTO soundtrack (id, soundtrack_name, path, hash, added) VALUES ($1, $2, $3, $4, now())
|
||||
`
|
||||
|
||||
type InsertSoundtrackWithExistingIdParams struct {
|
||||
ID int32 `json:"id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSoundtrackWithExistingId(ctx context.Context, arg InsertSoundtrackWithExistingIdParams) error {
|
||||
_, err := q.db.Exec(ctx, insertSoundtrackWithExistingId,
|
||||
arg.ID,
|
||||
arg.SoundtrackName,
|
||||
arg.Path,
|
||||
arg.Hash,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const removeSoundtrackDeletionDate = `-- name: RemoveSoundtrackDeletionDate :exec
|
||||
UPDATE soundtrack SET deleted=NULL WHERE id=$1
|
||||
`
|
||||
|
||||
func (q *Queries) RemoveSoundtrackDeletionDate(ctx context.Context, id int32) error {
|
||||
_, err := q.db.Exec(ctx, removeSoundtrackDeletionDate, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const resetSoundtrackIdSeq = `-- name: ResetSoundtrackIdSeq :one
|
||||
SELECT setval('soundtrack_id_seq', (SELECT MAX(id) FROM soundtrack)+1)
|
||||
`
|
||||
|
||||
func (q *Queries) ResetSoundtrackIdSeq(ctx context.Context) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, resetSoundtrackIdSeq)
|
||||
var setval int64
|
||||
err := row.Scan(&setval)
|
||||
return setval, err
|
||||
}
|
||||
|
||||
const setSoundtrackDeletionDate = `-- name: SetSoundtrackDeletionDate :exec
|
||||
UPDATE soundtrack SET deleted=now() WHERE deleted IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SetSoundtrackDeletionDate(ctx context.Context) error {
|
||||
_, err := q.db.Exec(ctx, setSoundtrackDeletionDate)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateSoundtrackHash = `-- name: UpdateSoundtrackHash :exec
|
||||
UPDATE soundtrack SET hash=$1, last_changed=now() WHERE id=$2
|
||||
`
|
||||
|
||||
type UpdateSoundtrackHashParams struct {
|
||||
Hash string `json:"hash"`
|
||||
ID int32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateSoundtrackHash(ctx context.Context, arg UpdateSoundtrackHashParams) error {
|
||||
_, err := q.db.Exec(ctx, updateSoundtrackHash, arg.Hash, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateSoundtrackName = `-- name: UpdateSoundtrackName :exec
|
||||
UPDATE soundtrack SET soundtrack_name=$1, path=$2, last_changed=now() WHERE id=$3
|
||||
`
|
||||
|
||||
type UpdateSoundtrackNameParams struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
ID int32 `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateSoundtrackName(ctx context.Context, arg UpdateSoundtrackNameParams) error {
|
||||
_, err := q.db.Exec(ctx, updateSoundtrackName, arg.Name, arg.Path, arg.ID)
|
||||
return err
|
||||
}
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
|
||||
const getLastPlayedGames = `-- name: GetLastPlayedGames :many
|
||||
SELECT
|
||||
g.id as game_id,
|
||||
g.game_name,
|
||||
g.times_played as game_played,
|
||||
g.last_played as game_last_played,
|
||||
g.id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.last_played as soundtrack_last_played,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'song_name', s.song_name,
|
||||
@@ -23,23 +23,23 @@ SELECT
|
||||
'times_played', s.times_played
|
||||
)
|
||||
) as songs
|
||||
FROM game g
|
||||
LEFT JOIN song s ON g.id = s.game_id
|
||||
FROM soundtrack g
|
||||
LEFT JOIN song s ON g.id = s.soundtrack_id
|
||||
WHERE g.deleted IS NULL AND g.last_played IS NOT NULL
|
||||
GROUP BY g.id, g.game_name, g.times_played, g.last_played
|
||||
GROUP BY g.id, g.soundtrack_name, g.times_played, g.last_played
|
||||
ORDER BY g.last_played DESC
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
type GetLastPlayedGamesRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
GamePlayed int32 `json:"game_played"`
|
||||
GameLastPlayed *time.Time `json:"game_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Last played games (most recently played)
|
||||
// Last played soundtracks (most recently played)
|
||||
func (q *Queries) GetLastPlayedGames(ctx context.Context, limit int32) ([]GetLastPlayedGamesRow, error) {
|
||||
rows, err := q.db.Query(ctx, getLastPlayedGames, limit)
|
||||
if err != nil {
|
||||
@@ -50,10 +50,10 @@ func (q *Queries) GetLastPlayedGames(ctx context.Context, limit int32) ([]GetLas
|
||||
for rows.Next() {
|
||||
var i GetLastPlayedGamesRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.GamePlayed,
|
||||
&i.GameLastPlayed,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -68,10 +68,10 @@ func (q *Queries) GetLastPlayedGames(ctx context.Context, limit int32) ([]GetLas
|
||||
|
||||
const getLeastPlayedGamesWithSongs = `-- name: GetLeastPlayedGamesWithSongs :many
|
||||
SELECT
|
||||
g.id as game_id,
|
||||
g.game_name,
|
||||
g.times_played as game_played,
|
||||
g.last_played as game_last_played,
|
||||
g.id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.last_played as soundtrack_last_played,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'song_name', s.song_name,
|
||||
@@ -80,23 +80,23 @@ SELECT
|
||||
'file_name', s.file_name
|
||||
)
|
||||
) as songs
|
||||
FROM game g
|
||||
LEFT JOIN song s ON g.id = s.game_id
|
||||
FROM soundtrack g
|
||||
LEFT JOIN song s ON g.id = s.soundtrack_id
|
||||
WHERE g.deleted IS NULL
|
||||
GROUP BY g.id, g.game_name, g.times_played, g.last_played
|
||||
ORDER BY g.times_played ASC, g.game_name
|
||||
GROUP BY g.id, g.soundtrack_name, g.times_played, g.last_played
|
||||
ORDER BY g.times_played ASC, g.soundtrack_name
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
type GetLeastPlayedGamesWithSongsRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
GamePlayed int32 `json:"game_played"`
|
||||
GameLastPlayed *time.Time `json:"game_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Least played games with their songs
|
||||
// Least played soundtracks with their songs
|
||||
func (q *Queries) GetLeastPlayedGamesWithSongs(ctx context.Context, limit int32) ([]GetLeastPlayedGamesWithSongsRow, error) {
|
||||
rows, err := q.db.Query(ctx, getLeastPlayedGamesWithSongs, limit)
|
||||
if err != nil {
|
||||
@@ -107,10 +107,10 @@ func (q *Queries) GetLeastPlayedGamesWithSongs(ctx context.Context, limit int32)
|
||||
for rows.Next() {
|
||||
var i GetLeastPlayedGamesWithSongsRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.GamePlayed,
|
||||
&i.GameLastPlayed,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -125,29 +125,29 @@ func (q *Queries) GetLeastPlayedGamesWithSongs(ctx context.Context, limit int32)
|
||||
|
||||
const getLeastPlayedSongsWithGame = `-- name: GetLeastPlayedSongsWithGame :many
|
||||
SELECT
|
||||
s.game_id as game_id,
|
||||
g.game_name,
|
||||
s.soundtrack_id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
s.song_name,
|
||||
s.path,
|
||||
s.times_played,
|
||||
s.file_name
|
||||
FROM song s
|
||||
JOIN game g ON s.game_id = g.id
|
||||
JOIN soundtrack g ON s.soundtrack_id = g.id
|
||||
WHERE g.deleted IS NULL
|
||||
ORDER BY s.times_played ASC, s.song_name
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
type GetLeastPlayedSongsWithGameRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
FileName *string `json:"file_name"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
FileName *string `json:"file_name"`
|
||||
}
|
||||
|
||||
// Least played songs with their game info
|
||||
// Least played songs with their soundtrack info
|
||||
func (q *Queries) GetLeastPlayedSongsWithGame(ctx context.Context, limit int32) ([]GetLeastPlayedSongsWithGameRow, error) {
|
||||
rows, err := q.db.Query(ctx, getLeastPlayedSongsWithGame, limit)
|
||||
if err != nil {
|
||||
@@ -158,8 +158,8 @@ func (q *Queries) GetLeastPlayedSongsWithGame(ctx context.Context, limit int32)
|
||||
for rows.Next() {
|
||||
var i GetLeastPlayedSongsWithGameRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SongName,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
@@ -177,10 +177,10 @@ func (q *Queries) GetLeastPlayedSongsWithGame(ctx context.Context, limit int32)
|
||||
|
||||
const getMostPlayedGamesWithSongs = `-- name: GetMostPlayedGamesWithSongs :many
|
||||
SELECT
|
||||
g.id as game_id,
|
||||
g.game_name,
|
||||
g.times_played as game_played,
|
||||
g.last_played as game_last_played,
|
||||
g.id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.last_played as soundtrack_last_played,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'song_name', s.song_name,
|
||||
@@ -189,23 +189,23 @@ SELECT
|
||||
'file_name', s.file_name
|
||||
)
|
||||
) as songs
|
||||
FROM game g
|
||||
LEFT JOIN song s ON g.id = s.game_id
|
||||
FROM soundtrack g
|
||||
LEFT JOIN song s ON g.id = s.soundtrack_id
|
||||
WHERE g.deleted IS NULL
|
||||
GROUP BY g.id, g.game_name, g.times_played, g.last_played
|
||||
ORDER BY g.times_played DESC, g.game_name
|
||||
GROUP BY g.id, g.soundtrack_name, g.times_played, g.last_played
|
||||
ORDER BY g.times_played DESC, g.soundtrack_name
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
type GetMostPlayedGamesWithSongsRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
GamePlayed int32 `json:"game_played"`
|
||||
GameLastPlayed *time.Time `json:"game_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Most played games with their songs
|
||||
// Most played soundtracks with their songs
|
||||
func (q *Queries) GetMostPlayedGamesWithSongs(ctx context.Context, limit int32) ([]GetMostPlayedGamesWithSongsRow, error) {
|
||||
rows, err := q.db.Query(ctx, getMostPlayedGamesWithSongs, limit)
|
||||
if err != nil {
|
||||
@@ -216,10 +216,10 @@ func (q *Queries) GetMostPlayedGamesWithSongs(ctx context.Context, limit int32)
|
||||
for rows.Next() {
|
||||
var i GetMostPlayedGamesWithSongsRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.GamePlayed,
|
||||
&i.GameLastPlayed,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -234,29 +234,29 @@ func (q *Queries) GetMostPlayedGamesWithSongs(ctx context.Context, limit int32)
|
||||
|
||||
const getMostPlayedSongsWithGame = `-- name: GetMostPlayedSongsWithGame :many
|
||||
SELECT
|
||||
s.game_id as game_id,
|
||||
g.game_name,
|
||||
s.soundtrack_id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
s.song_name,
|
||||
s.path,
|
||||
s.times_played,
|
||||
s.file_name
|
||||
FROM song s
|
||||
JOIN game g ON s.game_id = g.id
|
||||
JOIN soundtrack g ON s.soundtrack_id = g.id
|
||||
WHERE g.deleted IS NULL
|
||||
ORDER BY s.times_played DESC, s.song_name
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
type GetMostPlayedSongsWithGameRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
FileName *string `json:"file_name"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
FileName *string `json:"file_name"`
|
||||
}
|
||||
|
||||
// Most played songs with their game info
|
||||
// Most played songs with their soundtrack info
|
||||
func (q *Queries) GetMostPlayedSongsWithGame(ctx context.Context, limit int32) ([]GetMostPlayedSongsWithGameRow, error) {
|
||||
rows, err := q.db.Query(ctx, getMostPlayedSongsWithGame, limit)
|
||||
if err != nil {
|
||||
@@ -267,8 +267,8 @@ func (q *Queries) GetMostPlayedSongsWithGame(ctx context.Context, limit int32) (
|
||||
for rows.Next() {
|
||||
var i GetMostPlayedSongsWithGameRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SongName,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
@@ -286,9 +286,9 @@ func (q *Queries) GetMostPlayedSongsWithGame(ctx context.Context, limit int32) (
|
||||
|
||||
const getNeverPlayedGames = `-- name: GetNeverPlayedGames :many
|
||||
SELECT
|
||||
g.id as game_id,
|
||||
g.game_name,
|
||||
g.times_played as game_played,
|
||||
g.id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.added,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
@@ -297,19 +297,19 @@ SELECT
|
||||
'times_played', s.times_played
|
||||
)
|
||||
) as songs
|
||||
FROM game g
|
||||
LEFT JOIN song s ON g.id = s.game_id
|
||||
FROM soundtrack g
|
||||
LEFT JOIN song s ON g.id = s.soundtrack_id
|
||||
WHERE g.deleted IS NULL AND g.times_played = 0
|
||||
GROUP BY g.id, g.game_name, g.times_played, g.added
|
||||
ORDER BY g.game_name
|
||||
GROUP BY g.id, g.soundtrack_name, g.times_played, g.added
|
||||
ORDER BY g.soundtrack_name
|
||||
`
|
||||
|
||||
type GetNeverPlayedGamesRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
GamePlayed int32 `json:"game_played"`
|
||||
Added time.Time `json:"added"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
Added time.Time `json:"added"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Games that have never been played (times_played = 0)
|
||||
@@ -323,9 +323,9 @@ func (q *Queries) GetNeverPlayedGames(ctx context.Context) ([]GetNeverPlayedGame
|
||||
for rows.Next() {
|
||||
var i GetNeverPlayedGamesRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.GamePlayed,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.Added,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
@@ -341,10 +341,10 @@ func (q *Queries) GetNeverPlayedGames(ctx context.Context) ([]GetNeverPlayedGame
|
||||
|
||||
const getOldestPlayedGames = `-- name: GetOldestPlayedGames :many
|
||||
SELECT
|
||||
g.id as game_id,
|
||||
g.game_name,
|
||||
g.times_played as game_played,
|
||||
g.last_played as game_last_played,
|
||||
g.id as soundtrack_id,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.last_played as soundtrack_last_played,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'song_name', s.song_name,
|
||||
@@ -352,23 +352,23 @@ SELECT
|
||||
'times_played', s.times_played
|
||||
)
|
||||
) as songs
|
||||
FROM game g
|
||||
LEFT JOIN song s ON g.id = s.game_id
|
||||
FROM soundtrack g
|
||||
LEFT JOIN song s ON g.id = s.soundtrack_id
|
||||
WHERE g.deleted IS NULL AND g.last_played IS NOT NULL
|
||||
GROUP BY g.id, g.game_name, g.times_played, g.last_played
|
||||
GROUP BY g.id, g.soundtrack_name, g.times_played, g.last_played
|
||||
ORDER BY g.last_played ASC
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
type GetOldestPlayedGamesRow struct {
|
||||
GameID int32 `json:"game_id"`
|
||||
GameName string `json:"game_name"`
|
||||
GamePlayed int32 `json:"game_played"`
|
||||
GameLastPlayed *time.Time `json:"game_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Oldest played games (least recently played, but has been played at least once)
|
||||
// Oldest played soundtracks (least recently played, but has been played at least once)
|
||||
func (q *Queries) GetOldestPlayedGames(ctx context.Context, limit int32) ([]GetOldestPlayedGamesRow, error) {
|
||||
rows, err := q.db.Query(ctx, getOldestPlayedGames, limit)
|
||||
if err != nil {
|
||||
@@ -379,10 +379,10 @@ func (q *Queries) GetOldestPlayedGames(ctx context.Context, limit int32) ([]GetO
|
||||
for rows.Next() {
|
||||
var i GetOldestPlayedGamesRow
|
||||
if err := rows.Scan(
|
||||
&i.GameID,
|
||||
&i.GameName,
|
||||
&i.GamePlayed,
|
||||
&i.GameLastPlayed,
|
||||
&i.SoundtrackID,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -397,25 +397,25 @@ func (q *Queries) GetOldestPlayedGames(ctx context.Context, limit int32) ([]GetO
|
||||
|
||||
const getStatisticsSummary = `-- name: GetStatisticsSummary :one
|
||||
SELECT
|
||||
COUNT(*) as total_games,
|
||||
SUM(CASE WHEN times_played > 0 THEN 1 ELSE 0 END) as played_games,
|
||||
SUM(CASE WHEN times_played = 0 THEN 1 ELSE 0 END) as never_played_games,
|
||||
COALESCE(SUM(times_played), 0)::bigint as total_game_plays,
|
||||
COALESCE(AVG(times_played), 0)::float as avg_game_plays,
|
||||
COALESCE(MAX(times_played), 0)::bigint as max_game_plays,
|
||||
COALESCE(MIN(times_played), 0)::bigint as min_game_plays
|
||||
FROM game
|
||||
COUNT(*) as total_soundtracks,
|
||||
SUM(CASE WHEN times_played > 0 THEN 1 ELSE 0 END) as played_soundtracks,
|
||||
SUM(CASE WHEN times_played = 0 THEN 1 ELSE 0 END) as never_played_soundtracks,
|
||||
COALESCE(SUM(times_played), 0)::bigint as total_soundtrack_plays,
|
||||
COALESCE(AVG(times_played), 0)::float as avg_soundtrack_plays,
|
||||
COALESCE(MAX(times_played), 0)::bigint as max_soundtrack_plays,
|
||||
COALESCE(MIN(times_played), 0)::bigint as min_soundtrack_plays
|
||||
FROM soundtrack
|
||||
WHERE deleted IS NULL
|
||||
`
|
||||
|
||||
type GetStatisticsSummaryRow struct {
|
||||
TotalGames int64 `json:"total_games"`
|
||||
PlayedGames int64 `json:"played_games"`
|
||||
NeverPlayedGames int64 `json:"never_played_games"`
|
||||
TotalGamePlays int64 `json:"total_game_plays"`
|
||||
AvgGamePlays float64 `json:"avg_game_plays"`
|
||||
MaxGamePlays int64 `json:"max_game_plays"`
|
||||
MinGamePlays int64 `json:"min_game_plays"`
|
||||
TotalSoundtracks int64 `json:"total_soundtracks"`
|
||||
PlayedSoundtracks int64 `json:"played_soundtracks"`
|
||||
NeverPlayedSoundtracks int64 `json:"never_played_soundtracks"`
|
||||
TotalSoundtrackPlays int64 `json:"total_soundtrack_plays"`
|
||||
AvgSoundtrackPlays float64 `json:"avg_soundtrack_plays"`
|
||||
MaxSoundtrackPlays int64 `json:"max_soundtrack_plays"`
|
||||
MinSoundtrackPlays int64 `json:"min_soundtrack_plays"`
|
||||
}
|
||||
|
||||
// Get statistics summary
|
||||
@@ -423,13 +423,13 @@ func (q *Queries) GetStatisticsSummary(ctx context.Context) (GetStatisticsSummar
|
||||
row := q.db.QueryRow(ctx, getStatisticsSummary)
|
||||
var i GetStatisticsSummaryRow
|
||||
err := row.Scan(
|
||||
&i.TotalGames,
|
||||
&i.PlayedGames,
|
||||
&i.NeverPlayedGames,
|
||||
&i.TotalGamePlays,
|
||||
&i.AvgGamePlays,
|
||||
&i.MaxGamePlays,
|
||||
&i.MinGamePlays,
|
||||
&i.TotalSoundtracks,
|
||||
&i.PlayedSoundtracks,
|
||||
&i.NeverPlayedSoundtracks,
|
||||
&i.TotalSoundtrackPlays,
|
||||
&i.AvgSoundtrackPlays,
|
||||
&i.MaxSoundtrackPlays,
|
||||
&i.MinSoundtrackPlays,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user