sqlc: add album listing/search queries for Subsonic browse (#295)
Adds ListAlbumsAlphaByName, ListAlbumsAlphaByArtist (with sqlc.embed for the joined artist sort_name), ListAlbumsNewest, ListAlbumsRandom, ListAlbumsByGenre, and SearchAlbums. Powers getAlbumList2 type filters and the album facet of search3.
This commit is contained in:
@@ -20,3 +20,36 @@ SELECT * FROM albums WHERE artist_id = $1 AND title = $2 LIMIT 1;
|
||||
|
||||
-- name: ListAlbumsByArtist :many
|
||||
SELECT * FROM albums WHERE artist_id = $1 ORDER BY release_date NULLS LAST, sort_title;
|
||||
|
||||
-- name: ListAlbumsAlphaByName :many
|
||||
SELECT * FROM albums ORDER BY sort_title LIMIT $1 OFFSET $2;
|
||||
|
||||
-- name: ListAlbumsAlphaByArtist :many
|
||||
-- Sorted by the owning artist's sort_name. Needed by Subsonic's
|
||||
-- alphabeticalByArtist album list type.
|
||||
SELECT sqlc.embed(albums), artists.sort_name AS artist_sort_name
|
||||
FROM albums
|
||||
JOIN artists ON artists.id = albums.artist_id
|
||||
ORDER BY artists.sort_name, albums.sort_title
|
||||
LIMIT $1 OFFSET $2;
|
||||
|
||||
-- name: ListAlbumsNewest :many
|
||||
SELECT * FROM albums ORDER BY created_at DESC LIMIT $1 OFFSET $2;
|
||||
|
||||
-- name: ListAlbumsRandom :many
|
||||
SELECT * FROM albums ORDER BY random() LIMIT $1;
|
||||
|
||||
-- name: ListAlbumsByGenre :many
|
||||
-- Album "belongs to" a genre if any of its tracks carry that genre.
|
||||
SELECT DISTINCT ON (albums.id) albums.*
|
||||
FROM albums
|
||||
JOIN tracks ON tracks.album_id = albums.id
|
||||
WHERE tracks.genre = $1
|
||||
ORDER BY albums.id, albums.sort_title
|
||||
LIMIT $2 OFFSET $3;
|
||||
|
||||
-- name: SearchAlbums :many
|
||||
SELECT * FROM albums
|
||||
WHERE title ILIKE '%' || $1 || '%'
|
||||
ORDER BY sort_title
|
||||
LIMIT $2 OFFSET $3;
|
||||
|
||||
Reference in New Issue
Block a user