| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const string = []const u8; |
| 2 | const sqlite = @import("sqlite"); | 3 | const sqlite = @import("sqlite"); |
| 3 | | 4 | |
| 4 | const Self = @This(); | 5 | const Self = @This(); |
| ... | @@ -24,8 +25,8 @@ pub fn close(self: *Self) void { | ... | @@ -24,8 +25,8 @@ pub fn close(self: *Self) void { |
| 24 | self.db.deinit(); | 25 | self.db.deinit(); |
| 25 | } | 26 | } |
| 26 | | 27 | |
| 27 | pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: []const u8, args: anytype) ![]const T { | | |
| 28 | var stmt = try self.db.prepare(query); | 28 | var stmt = try self.db.prepare(query); |
| | 29 | pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]const T { |
| 29 | defer stmt.deinit(); | 30 | defer stmt.deinit(); |
| 30 | var iter = try stmt.iteratorAlloc(T, alloc, args); | 31 | var iter = try stmt.iteratorAlloc(T, alloc, args); |
| 31 | var list = std.ArrayList(T).init(alloc); | 32 | var list = std.ArrayList(T).init(alloc); |
| ... | @@ -35,13 +36,13 @@ pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptim | ... | @@ -35,13 +36,13 @@ pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptim |
| 35 | return list.toOwnedSlice(); | 36 | return list.toOwnedSlice(); |
| 36 | } | 37 | } |
| 37 | | 38 | |
| 38 | pub fn exec(self: *Self, alloc: *std.mem.Allocator, comptime query: []const u8, args: anytype) !void { | 39 | pub fn exec(self: *Self, alloc: *std.mem.Allocator, comptime query: string, args: anytype) !void { |
| 39 | var stmt = try self.db.prepare(query); | 40 | var stmt = try self.db.prepare(query); |
| 40 | defer stmt.deinit(); | 41 | defer stmt.deinit(); |
| 41 | try stmt.execAlloc(.{ .allocator = alloc }, args); | 42 | try stmt.execAlloc(.{ .allocator = alloc }, args); |
| 42 | } | 43 | } |
| 43 | | 44 | |
| 44 | pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: []const u8, args: anytype) !?T { | 45 | pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { |
| 45 | var stmt = try self.db.prepare(query); | 46 | var stmt = try self.db.prepare(query); |
| 46 | defer stmt.deinit(); | 47 | defer stmt.deinit(); |
| 47 | return try stmt.oneAlloc(T, alloc, .{}, args); | 48 | return try stmt.oneAlloc(T, alloc, .{}, args); |