authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-05 00:57:53 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-05 00:57:53 -07:00
logc5cad45bcb9d90a0ea2f9b91f2d61a3fcbabe8a7
tree2f826b7efed3ee44dab21d35544333a03972677e
parentcd4471bb573fc17e479a67e9556ae8760c20de5c

collect: return a mutable slice since it doesnt need to be const


1 files changed, 2 insertions(+), 1 deletions(-)

src/sqlite3.zig+2-1
...@@ -32,11 +32,12 @@ fn prepare(self: *Self, comptime query: string) !sqlite.StatementType(.{}, query...@@ -32,11 +32,12 @@ fn prepare(self: *Self, comptime query: string) !sqlite.StatementType(.{}, query
32 };32 };
33}33}
3434
35pub fn collect(self: *Self, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]const T {35pub fn collect(self: *Self, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]T {
36 var stmt = try self.prepare(query);36 var stmt = try self.prepare(query);
37 defer stmt.deinit();37 defer stmt.deinit();
38 var iter = try stmt.iteratorAlloc(T, alloc, args);38 var iter = try stmt.iteratorAlloc(T, alloc, args);
39 var list = std.ArrayList(T).init(alloc);39 var list = std.ArrayList(T).init(alloc);
40 errdefer list.deinit();
40 while (try iter.nextAlloc(alloc, .{})) |row| {41 while (try iter.nextAlloc(alloc, .{})) |row| {
41 try list.append(row);42 try list.append(row);
42 }43 }