authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:31:44 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:31:44 -07:00
log3f56910018b4b6b067ff5ce2891fd858c3bc0ebf
treed3d7cd1093640a59b3728b446d57e3315c1f1dcd
parentcaaf5d24b97c2f016c5c44131cd5b8507d1d5082

add string alias


1 files changed, 4 insertions(+), 3 deletions(-)

src/sqlite3.zig+4-3
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const sqlite = @import("sqlite");3const sqlite = @import("sqlite");
34
4const Self = @This();5const 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}
2627
27pub 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);
29pub 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}
3738
38pub fn exec(self: *Self, alloc: *std.mem.Allocator, comptime query: []const u8, args: anytype) !void {39pub 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}
4344
44pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: []const u8, args: anytype) !?T {45pub 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);