// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: queue.sql package repository import ( "context" "github.com/google/uuid" ) const addLastFetchedToQueue = `-- name: AddLastFetchedToQueue :exec WITH added AS ( INSERT INTO queue_song (queue_uuid, song_no, song_uuid, soundtrack_name, song_name, mode) SELECT q.uuid, (SELECT COALESCE(MAX(qs.song_no), -1) + 1 FROM queue_song qs WHERE qs.queue_uuid = q.uuid), s.uuid, st.soundtrack_name, s.song_name, COALESCE(q.last_fetched_mode, 'unknown') FROM queue q JOIN song s ON s.uuid = q.last_fetched_song_uuid JOIN soundtrack st ON st.id = s.soundtrack_id WHERE q.uuid = $1 RETURNING queue_uuid, song_no ) UPDATE queue SET current_song = added.song_no, last_fetched_song_uuid = NULL, last_fetched_mode = NULL FROM added WHERE queue.uuid = added.queue_uuid ` // Appends the queue's last fetched song and makes it the current song. // Does nothing when no song has been fetched since the last call. func (q *Queries) AddLastFetchedToQueue(ctx context.Context, argUuid uuid.UUID) error { _, err := q.db.Exec(ctx, addLastFetchedToQueue, argUuid) return err } const createQueue = `-- name: CreateQueue :one INSERT INTO queue DEFAULT VALUES RETURNING uuid, current_song, last_fetched_song_uuid, last_fetched_mode, started_at, ended_at ` func (q *Queries) CreateQueue(ctx context.Context) (Queue, error) { row := q.db.QueryRow(ctx, createQueue) var i Queue err := row.Scan( &i.Uuid, &i.CurrentSong, &i.LastFetchedSongUuid, &i.LastFetchedMode, &i.StartedAt, &i.EndedAt, ) return i, err } const endActiveQueues = `-- name: EndActiveQueues :exec UPDATE queue SET ended_at = NOW() WHERE ended_at IS NULL ` func (q *Queries) EndActiveQueues(ctx context.Context) error { _, err := q.db.Exec(ctx, endActiveQueues) return err } const endQueue = `-- name: EndQueue :exec UPDATE queue SET ended_at = NOW() WHERE uuid = $1 AND ended_at IS NULL ` func (q *Queries) EndQueue(ctx context.Context, argUuid uuid.UUID) error { _, err := q.db.Exec(ctx, endQueue, argUuid) return err } const getQueue = `-- name: GetQueue :one SELECT uuid, current_song, last_fetched_song_uuid, last_fetched_mode, started_at, ended_at FROM queue WHERE uuid = $1 ` func (q *Queries) GetQueue(ctx context.Context, argUuid uuid.UUID) (Queue, error) { row := q.db.QueryRow(ctx, getQueue, argUuid) var i Queue err := row.Scan( &i.Uuid, &i.CurrentSong, &i.LastFetchedSongUuid, &i.LastFetchedMode, &i.StartedAt, &i.EndedAt, ) return i, err } const listQueueSongs = `-- name: ListQueueSongs :many SELECT qs.song_no, qs.song_uuid, qs.soundtrack_name, qs.song_name, qs.mode, s.path, s.times_played, s.soundtrack_uuid FROM queue_song qs LEFT JOIN song s ON s.uuid = qs.song_uuid WHERE qs.queue_uuid = $1 ORDER BY qs.song_no ` type ListQueueSongsRow struct { SongNo int32 `json:"song_no"` SongUuid uuid.UUID `json:"song_uuid"` SoundtrackName string `json:"soundtrack_name"` SongName string `json:"song_name"` Mode string `json:"mode"` Path *string `json:"path"` TimesPlayed *int32 `json:"times_played"` SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"` } // The song columns are NULL when the song has been removed from the library since. func (q *Queries) ListQueueSongs(ctx context.Context, queueUuid uuid.UUID) ([]ListQueueSongsRow, error) { rows, err := q.db.Query(ctx, listQueueSongs, queueUuid) if err != nil { return nil, err } defer rows.Close() var items []ListQueueSongsRow for rows.Next() { var i ListQueueSongsRow if err := rows.Scan( &i.SongNo, &i.SongUuid, &i.SoundtrackName, &i.SongName, &i.Mode, &i.Path, &i.TimesPlayed, &i.SoundtrackUuid, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const setQueueCurrentSong = `-- name: SetQueueCurrentSong :exec UPDATE queue SET current_song = $2 WHERE uuid = $1 ` type SetQueueCurrentSongParams struct { Uuid uuid.UUID `json:"uuid"` CurrentSong int32 `json:"current_song"` } func (q *Queries) SetQueueCurrentSong(ctx context.Context, arg SetQueueCurrentSongParams) error { _, err := q.db.Exec(ctx, setQueueCurrentSong, arg.Uuid, arg.CurrentSong) return err } const setQueueLastFetched = `-- name: SetQueueLastFetched :exec UPDATE queue SET last_fetched_song_uuid = $2, last_fetched_mode = $3 WHERE uuid = $1 ` type SetQueueLastFetchedParams struct { Uuid uuid.UUID `json:"uuid"` LastFetchedSongUuid uuid.UUID `json:"last_fetched_song_uuid"` LastFetchedMode *string `json:"last_fetched_mode"` } func (q *Queries) SetQueueLastFetched(ctx context.Context, arg SetQueueLastFetchedParams) error { _, err := q.db.Exec(ctx, setQueueLastFetched, arg.Uuid, arg.LastFetchedSongUuid, arg.LastFetchedMode) return err }