Split entity_items and appears query into more granular queries
We can be a bit more specific about the information we get this way
This commit is contained in:
parent
adcaff34ea
commit
3ef17fcd46
4 changed files with 69 additions and 32 deletions
|
|
@ -20,7 +20,7 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
||||||
const album = try queries.entityQueryResult(request, queries.loadQuery(.album, .entity_info), .{id});
|
const album = try queries.entityQueryResult(request, queries.loadQuery(.album, .entity_info), .{id});
|
||||||
try root.put("album", album);
|
try root.put("album", album);
|
||||||
|
|
||||||
const songs = try queries.entityQueryResult(request, queries.loadQuery(.album, .entity_items), .{id});
|
const songs = try queries.entityQueryResult(request, queries.loadQuery(.album, .get_songs), .{id});
|
||||||
try root.put("songs", songs);
|
try root.put("songs", songs);
|
||||||
|
|
||||||
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.album, .firstlast), .{id});
|
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.album, .firstlast), .{id});
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
||||||
const artist = try queries.entityQueryResult(request, queries.loadQuery(.artist, .entity_info), .{id});
|
const artist = try queries.entityQueryResult(request, queries.loadQuery(.artist, .entity_info), .{id});
|
||||||
try root.put("artist", artist);
|
try root.put("artist", artist);
|
||||||
|
|
||||||
const albums = try queries.entityQueryResult(request, queries.loadQuery(.artist, .entity_items), .{id});
|
const albums = try queries.entityQueryResult(request, queries.loadQuery(.artist, .get_albums), .{id});
|
||||||
try root.put("albums", albums);
|
try root.put("albums", albums);
|
||||||
|
|
||||||
const appears = try queries.entityQueryResult(request, queries.loadQuery(.artist, .appears), .{id});
|
const appears = try queries.entityQueryResult(request, queries.loadQuery(.artist, .appears), .{id});
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
||||||
const song = try queries.entityQueryResult(request, queries.loadQuery(.song, .entity_info), .{id});
|
const song = try queries.entityQueryResult(request, queries.loadQuery(.song, .entity_info), .{id});
|
||||||
try root.put("song", song);
|
try root.put("song", song);
|
||||||
|
|
||||||
const scrobbles = try queries.entityQueryResult(request, queries.loadQuery(.song, .entity_items), .{id});
|
const scrobbles = try queries.entityQueryResult(request, queries.loadQuery(.song, .get_scrobbles), .{id});
|
||||||
try root.put("scrobbles", scrobbles);
|
try root.put("scrobbles", scrobbles);
|
||||||
|
|
||||||
const appears = try queries.entityQueryResult(request, queries.loadQuery(.song, .appears), .{id});
|
const albums = try queries.entityQueryResult(request, queries.loadQuery(.song, .get_albums), .{id});
|
||||||
try root.put("appears", appears);
|
try root.put("albums", albums);
|
||||||
|
|
||||||
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.song, .firstlast), .{id});
|
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.song, .firstlast), .{id});
|
||||||
try root.put("firstlast", firstlast);
|
try root.put("firstlast", firstlast);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ pub fn entityQueryResult(request: *jetzig.Request, query: GeneratedQuery, args:
|
||||||
}
|
}
|
||||||
|
|
||||||
const EntityType = enum { scrobble, song, album, artist };
|
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, get_songs, get_albums, get_scrobbles, appears, entity_info, datestreak };
|
||||||
|
|
||||||
const GeneratedQuery = struct {
|
const GeneratedQuery = struct {
|
||||||
entity: EntityType,
|
entity: EntityType,
|
||||||
|
|
@ -246,20 +246,9 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
|
||||||
},
|
},
|
||||||
|
|
||||||
.appears =>
|
.appears =>
|
||||||
//.ResultType = AppearsResult,
|
// Not sure how I feel about this one
|
||||||
switch (entity) {
|
switch (entity) {
|
||||||
.scrobble, .album => unreachable,
|
.scrobble, .song, .album => unreachable,
|
||||||
.song =>
|
|
||||||
\\SELECT albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
|
||||||
\\FROM artistalbums
|
|
||||||
\\INNER JOIN albums ON albums.id = artistalbums.album_id
|
|
||||||
\\INNER JOIN albumsongs ON albumsongs.album_id = albums.id
|
|
||||||
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
|
||||||
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
|
||||||
\\WHERE albumsongs.song_id = $1
|
|
||||||
\\GROUP BY albums.id
|
|
||||||
\\ORDER BY scrobbles DESC;
|
|
||||||
,
|
|
||||||
.artist =>
|
.artist =>
|
||||||
\\SELECT albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
\\SELECT albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
||||||
\\FROM artistalbums
|
\\FROM artistalbums
|
||||||
|
|
@ -273,19 +262,8 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
|
||||||
,
|
,
|
||||||
},
|
},
|
||||||
|
|
||||||
.entity_items =>
|
.get_songs => switch (entity) {
|
||||||
//.ResultType = EntityItemsResult,
|
.scrobble, .song => unreachable, // Might be able to use this with SongGroups?
|
||||||
switch (entity) {
|
|
||||||
.scrobble => unreachable,
|
|
||||||
.song =>
|
|
||||||
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, TO_CHAR(scrobbles.datetime, 'YYYY-MM-DD HH24:MI:SS') AS date
|
|
||||||
\\FROM albumsongs
|
|
||||||
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
|
||||||
\\INNER JOIN songs ON songs.id = albumsongs.song_id
|
|
||||||
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
|
||||||
\\WHERE songs.id = $1
|
|
||||||
\\ORDER BY date ASC
|
|
||||||
,
|
|
||||||
.album =>
|
.album =>
|
||||||
\\SELECT songs.name AS song_name, songs.id AS song_id, COUNT(scrobbles) AS scrobbles
|
\\SELECT songs.name AS song_name, songs.id AS song_id, COUNT(scrobbles) AS scrobbles
|
||||||
\\FROM albumsongs
|
\\FROM albumsongs
|
||||||
|
|
@ -296,6 +274,34 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
|
||||||
\\ORDER BY scrobbles DESC
|
\\ORDER BY scrobbles DESC
|
||||||
,
|
,
|
||||||
.artist =>
|
.artist =>
|
||||||
|
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
||||||
|
\\FROM albumsongs
|
||||||
|
\\INNER JOIN songs ON songs.id = albumsongs.song_id
|
||||||
|
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
||||||
|
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
||||||
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
|
\\WHERE albumsongsartists.artist_id = $1
|
||||||
|
\\GROUP BY songs.id, albums.id
|
||||||
|
\\ORDER BY scrobbles DESC
|
||||||
|
,
|
||||||
|
},
|
||||||
|
|
||||||
|
.get_albums =>
|
||||||
|
//.ResultType = EntityItemsResult,
|
||||||
|
switch (entity) {
|
||||||
|
.scrobble, .album => unreachable, // Might be able to use this with ReleaseGroups?
|
||||||
|
.song =>
|
||||||
|
\\SELECT albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
||||||
|
\\FROM artistalbums
|
||||||
|
\\INNER JOIN albums ON albums.id = artistalbums.album_id
|
||||||
|
\\INNER JOIN albumsongs ON albumsongs.album_id = albums.id
|
||||||
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
|
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
||||||
|
\\WHERE albumsongs.song_id = $1
|
||||||
|
\\GROUP BY albums.id
|
||||||
|
\\ORDER BY scrobbles DESC
|
||||||
|
,
|
||||||
|
.artist =>
|
||||||
\\SELECT albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
\\SELECT albums.name AS album_name, albums.id AS album_id, COUNT(scrobbles) AS scrobbles
|
||||||
\\FROM artistalbums
|
\\FROM artistalbums
|
||||||
\\INNER JOIN albums ON albums.id = artistalbums.album_id
|
\\INNER JOIN albums ON albums.id = artistalbums.album_id
|
||||||
|
|
@ -307,6 +313,37 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
|
||||||
,
|
,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.get_scrobbles => switch (entity) {
|
||||||
|
.scrobble => unreachable,
|
||||||
|
.song =>
|
||||||
|
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, TO_CHAR(scrobbles.datetime, 'YYYY-MM-DD HH24:MI:SS') AS date
|
||||||
|
\\FROM albumsongs
|
||||||
|
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
||||||
|
\\INNER JOIN songs ON songs.id = albumsongs.song_id
|
||||||
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
|
\\WHERE songs.id = $1
|
||||||
|
\\ORDER BY date ASC
|
||||||
|
,
|
||||||
|
.album =>
|
||||||
|
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, TO_CHAR(scrobbles.datetime, 'YYYY-MM-DD HH24:MI:SS') AS date
|
||||||
|
\\FROM albumsongs
|
||||||
|
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
||||||
|
\\INNER JOIN songs ON songs.id = albumsongs.song_id
|
||||||
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
|
\\WHERE albums.id = $1
|
||||||
|
\\ORDER BY date ASC
|
||||||
|
,
|
||||||
|
.artist =>
|
||||||
|
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, TO_CHAR(scrobbles.datetime, 'YYYY-MM-DD HH24:MI:SS') AS date
|
||||||
|
\\FROM albumsongs
|
||||||
|
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
||||||
|
\\INNER JOIN songs ON songs.id = albumsongs.song_id
|
||||||
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
|
\\WHERE artists.id = $1
|
||||||
|
\\ORDER BY date ASC
|
||||||
|
,
|
||||||
|
},
|
||||||
|
|
||||||
.entity_info => switch (entity) {
|
.entity_info => switch (entity) {
|
||||||
.scrobble => unreachable,
|
.scrobble => unreachable,
|
||||||
.song =>
|
.song =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue