diff --git a/src/queries.zig b/src/queries.zig index 8db7809..adb1447 100644 --- a/src/queries.zig +++ b/src/queries.zig @@ -55,7 +55,7 @@ pub fn entityQueryResult(request: *jetzig.Request, query: GeneratedQuery, args: } const EntityType = enum { scrobble, song, album, artist }; -const QueryTypeEnum = enum { firstlast, timescale, entities, entity_items, appears, entity_info, datestreak }; +const QueryTypeEnum = enum { firstlast, timescale, entities, entity_items, appears, entity_info, datestreak, entities_by_name }; const GeneratedQuery = struct { entity: EntityType, @@ -215,13 +215,14 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery { \\ORDER BY scrobbles.datetime ASC , .song => - \\SELECT songs.name AS song_name, songs.id AS song_id, artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles + \\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles \\FROM albumsongs \\INNER JOIN songs ON albumsongs.song_id = songs.id \\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id \\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id \\INNER JOIN artists ON artists.id = albumsongsartists.artist_id - \\GROUP BY songs.id, artists.id + \\INNER JOIN albums ON albums.id = albumsongs.album_id + \\GROUP BY songs.id, albums.id, artists.id \\ORDER BY scrobbles DESC, songs.name ASC , .album => @@ -388,6 +389,21 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery { , .scrobble => unreachable, }, + .entities_by_name => switch (entity) { + .song => + \\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles + \\FROM albumsongs + \\INNER JOIN songs ON albumsongs.song_id = songs.id + \\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id + \\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id + \\INNER JOIN artists ON artists.id = albumsongsartists.artist_id + \\INNER JOIN albums ON albums.id = albumsongs.album_id + \\WHERE LOWER(songs.name) LIKE LOWER($1) + \\GROUP BY songs.id, albums.id, artists.id + \\ORDER BY songs.name ASC, scrobbles DESC; + , + else => unreachable, + }, }, }; }