diff --git a/build.zig.zon b/build.zig.zon index 6abba12..d5fa9fa 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -16,8 +16,8 @@ // internet connectivity. .dependencies = .{ .jetzig = .{ - .url = "https://github.com/jetzig-framework/jetzig/archive/da2978ed04c1248faa06cbcbf1d0a284afeddb5e.tar.gz", - .hash = "1220d2bf337c4a878e88087cc56b44d4a71b0a33e7b57eaedd1b765e3a775865f18a", + .url = "https://github.com/jetzig-framework/jetzig/archive/8a4f91f26a5d6a9b34a47011e63e779280590bc2.tar.gz", + .hash = "1220dac633f4b6a3c40d2b8d5a3cb2fdd513601eb762ccb15c418e0646923d42cfe9", }, .zeit = .{ .url = "https://github.com/rockorager/zeit/archive/refs/heads/main.tar.gz", diff --git a/common_queries.md b/common_queries.md index 8344358..3363494 100644 --- a/common_queries.md +++ b/common_queries.md @@ -1,3 +1,7 @@ +> [!note] Notice +> Queries involving artists are likely inaccurate due to database structure and +> limitations of scrobbles. Specifics and fixes are being planned. + Get all albums from specified artist: ```sql SELECT artists.name, albums.name @@ -39,3 +43,55 @@ WHERE songs.id = scrobbles.song_id GROUP BY songs.id ORDER BY scount DESC; ``` + +Sort all songs by plays, and include artist: +```sql +SELECT songs.name, artists.name, COUNT(scrobbles.song_id) AS scount +FROM scrobbles, "Songartists" +INNER JOIN artists +ON "Songartists".artist_id = artists.id +INNER JOIN songs +ON "Songartists".song_id = songs.id +WHERE songs.id = scrobbles.song_id +GROUP BY songs.id, artists.id +ORDER BY scount DESC; +``` + +Sort all songs by plays, and include artist and album: +```sql +SELECT songs.name, artists.name, albums.name, COUNT(scrobbles.song_id) AS scount +FROM scrobbles CROSS JOIN "Songartists" CROSS JOIN "Albumsongs" +INNER JOIN artists +ON "Songartists".artist_id = artists.id +INNER JOIN songs +ON "Songartists".song_id = songs.id AND "Albumsongs".song_id = songs.id +INNER JOIN albums +ON "Albumsongs".album_id = albums.id +WHERE songs.id = scrobbles.song_id +GROUP BY songs.id, artists.id, albums.id +ORDER BY scount DESC; +``` + +Sort all albums by plays, and include artist: +```sql +SELECT albums.name, artists.name, COUNT(scrobbles.album_id) AS scount +FROM scrobbles, "Albumartists" +INNER JOIN albums +ON "Albumartists".album_id = albums.id +INNER JOIN artists +ON "Albumartists".artist_id = artists.id +WHERE albums.id = scrobbles.album_id +GROUP BY artists.id, albums.id +ORDER BY scount DESC; +``` + +Sort all artists by plays: +```sql +SELECT artists.name, COUNT(scrobbles.id) AS scount +FROM artists, "Scrobbleartists" +INNER JOIN scrobbles +ON scrobbles.id = "Scrobbleartists".scrobble_id +WHERE "Scrobbleartists".artist_id = artists.id +GROUP BY artists.id +zuletzt_dev-# ORDER BY scount DESC; +``` diff --git a/src/app/jobs/process_scrobbles.zig b/src/app/jobs/process_scrobbles.zig index ee308cb..1314465 100644 --- a/src/app/jobs/process_scrobbles.zig +++ b/src/app/jobs/process_scrobbles.zig @@ -100,7 +100,9 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig if (associative_table_flags[2]) try jetzig.database.Query(.Songartist).insert(.{ .song_id = song_id, .artist_id = artist_id }).execute(env.repo); } - try jetzig.database.Query(.Scrobble).insert(.{ .song_id = song_id, .album_id = album_id, .date = scrobble.date }).execute(env.repo); + const scr_id = try jetzig.database.Query(.Scrobble).insert(.{ .song_id = song_id, .album_id = album_id, .date = scrobble.date }).returning(.{.id}).execute(env.repo); + defer env.repo.free(scr_id); + try jetzig.database.Query(.Scrobbleartist).insert(.{ .scrobble_id = scr_id.?.id, .artist_id = artist_id }).execute(env.repo); } } diff --git a/src/app/views/upload/index.zmpl b/src/app/views/upload/index.zmpl index da56583..7b45aad 100644 --- a/src/app/views/upload/index.zmpl +++ b/src/app/views/upload/index.zmpl @@ -16,9 +16,9 @@