Made queries.zig look significantly nicer

There's a little bit of weird stuff happening, but holy cannoli, that's so much easier to maintain and parse
This commit is contained in:
mitteneer 2025-05-29 19:39:51 -04:00
parent d638fa66c5
commit 62590fee37
7 changed files with 87 additions and 140 deletions

View file

@ -8,7 +8,7 @@ const queries = @import("../../queries.zig");
pub fn index(request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const albums = try queries.entityQueryResult(request, queries.generateQuery(.album, .entities), .{}, .array);
const albums = try queries.entityQueryResult(request, queries.loadQuery(.album, .entities), .{});
try root.put("albums", albums);
return request.render(.ok);
@ -17,16 +17,16 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const album = try queries.entityQueryResult(request, queries.generateQuery(.album, .entity_info), .{id}, .object);
try root.put("album", album.get("entity_info"));
const album = try queries.entityQueryResult(request, queries.loadQuery(.album, .entity_info), .{id});
try root.put("album", album);
const songs = try queries.entityQueryResult(request, queries.generateQuery(.album, .entity_items), .{id}, .array);
const songs = try queries.entityQueryResult(request, queries.loadQuery(.album, .entity_items), .{id});
try root.put("songs", songs);
const firstlast = try queries.entityQueryResult(request, queries.generateQuery(.album, .firstlast), .{id}, .array);
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.album, .firstlast), .{id});
try root.put("firstlast", firstlast);
const timescale = try queries.entityQueryResult(request, queries.generateQuery(.album, .timescale), .{id}, .array);
const timescale = try queries.entityQueryResult(request, queries.loadQuery(.album, .timescale), .{id});
try root.put("yearly", timescale);
return request.render(.ok);

View file

@ -8,7 +8,7 @@ const queries = @import("../../queries.zig");
pub fn index(request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const artists = try queries.entityQueryResult(request, queries.generateQuery(.artist, .entities), .{}, .array);
const artists = try queries.entityQueryResult(request, queries.loadQuery(.artist, .entities), .{});
try root.put("artists", artists);
@ -18,19 +18,19 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const artist = try queries.entityQueryResult(request, queries.generateQuery(.artist, .entity_info), .{id}, .object);
try root.put("artist", artist.get("entity_info"));
const artist = try queries.entityQueryResult(request, queries.loadQuery(.artist, .entity_info), .{id});
try root.put("artist", artist);
const albums = try queries.entityQueryResult(request, queries.generateQuery(.artist, .entity_items), .{id}, .array);
const albums = try queries.entityQueryResult(request, queries.loadQuery(.artist, .entity_items), .{id});
try root.put("albums", albums);
const appears = try queries.entityQueryResult(request, queries.generateQuery(.artist, .appears), .{id}, .array);
const appears = try queries.entityQueryResult(request, queries.loadQuery(.artist, .appears), .{id});
try root.put("appears", appears);
const firstlast = try queries.entityQueryResult(request, queries.generateQuery(.artist, .firstlast), .{id}, .array);
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.artist, .firstlast), .{id});
try root.put("firstlast", firstlast);
const timescale = try queries.entityQueryResult(request, queries.generateQuery(.artist, .timescale), .{id}, .array);
const timescale = try queries.entityQueryResult(request, queries.loadQuery(.artist, .timescale), .{id});
try root.put("yearly", timescale);
return request.render(.ok);

View file

@ -7,7 +7,7 @@
<div>
{{scrobbles}} scrobbles ({{rank}} place)
<br>
First listen: <a href="/songs/{{songs[0].id}}">{{songs[0].name}}</a> ({{songs[0].date}})
First listen: <a href="/songs/{{songs[0].song.id}}">{{songs[0].song.name}}</a> ({{songs[0].date}})
<br>
Most recent listen: <a href="/songs/{{songs[1].id}}">{{songs[1].name}}</a> ({{songs[1].date}})
Most recent listen: <a href="/songs/{{songs[1].song.id}}">{{songs[1].song.name}}</a> ({{songs[1].date}})
</div>

View file

@ -10,7 +10,7 @@
<tbody>
@for (range) |itm| {
<tr>
<td>{{itm.year}}:</td>
<td>{{itm.date}}:</td>
<td>{{itm.scrobbles}}</td>
</tr>
}

View file

@ -5,7 +5,7 @@ const queries = @import("../../queries.zig");
pub fn index(request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const scrobbles = try queries.entityQueryResult(request, queries.generateQuery(.scrobble, .entities), .{}, .array);
const scrobbles = try queries.entityQueryResult(request, queries.loadQuery(.scrobble, .entities), .{});
try root.put("scrobbles", scrobbles);
return request.render(.ok);

View file

@ -5,7 +5,7 @@ const queries = @import("../../queries.zig");
pub fn index(request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const songs = try queries.entityQueryResult(request, queries.generateQuery(.song, .entities), .{}, .array);
const songs = try queries.entityQueryResult(request, queries.loadQuery(.song, .entities), .{});
try root.put("songs", songs);
return request.render(.ok);
@ -14,19 +14,19 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
var root = try request.data(.object);
const song = try queries.entityQueryResult(request, queries.generateQuery(.song, .entity_info), .{id}, .object);
try root.put("song", song.get("entity_info"));
const song = try queries.entityQueryResult(request, queries.loadQuery(.song, .entity_info), .{id});
try root.put("song", song);
const scrobbles = try queries.entityQueryResult(request, queries.generateQuery(.song, .entity_items), .{id}, .array);
const scrobbles = try queries.entityQueryResult(request, queries.loadQuery(.song, .entity_items), .{id});
try root.put("scrobbles", scrobbles);
const appears = try queries.entityQueryResult(request, queries.generateQuery(.song, .appears), .{id}, .array);
const appears = try queries.entityQueryResult(request, queries.loadQuery(.song, .appears), .{id});
try root.put("appears", appears);
const firstlast = try queries.entityQueryResult(request, queries.generateQuery(.song, .firstlast), .{id}, .array);
const firstlast = try queries.entityQueryResult(request, queries.loadQuery(.song, .firstlast), .{id});
try root.put("firstlast", firstlast);
const timescale = try queries.entityQueryResult(request, queries.generateQuery(.song, .timescale), .{id}, .array);
const timescale = try queries.entityQueryResult(request, queries.loadQuery(.song, .timescale), .{id});
try root.put("yearly", timescale);
return request.render(.ok);
}