| ... | ... | @@ -32,7 +32,7 @@ fn prepare(self: *Self, comptime query: string) !sqlite.StatementType(.{}, query |
| 32 | 32 | }; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | | pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]const T { |
| 35 | pub fn collect(self: *Self, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]const T { |
| 36 | 36 | var stmt = try self.prepare(query); |
| 37 | 37 | defer stmt.deinit(); |
| 38 | 38 | var iter = try stmt.iteratorAlloc(T, alloc, args); |
| ... | ... | @@ -43,19 +43,19 @@ pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptim |
| 43 | 43 | return list.toOwnedSlice(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | | pub fn exec(self: *Self, alloc: *std.mem.Allocator, comptime query: string, args: anytype) !void { |
| 46 | pub fn exec(self: *Self, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void { |
| 47 | 47 | var stmt = try self.prepare(query); |
| 48 | 48 | defer stmt.deinit(); |
| 49 | 49 | try stmt.execAlloc(alloc, .{}, args); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | | pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { |
| 52 | pub fn first(self: *Self, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { |
| 53 | 53 | var stmt = try self.prepare(query); |
| 54 | 54 | defer stmt.deinit(); |
| 55 | 55 | return try stmt.oneAlloc(T, alloc, .{}, args); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | | pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !bool { |
| 58 | pub fn doesTableExist(self: *Self, alloc: std.mem.Allocator, name: string) !bool { |
| 59 | 59 | for (try self.collect(alloc, string, "select name from sqlite_master where type=? AND name=?", .{ .type = "table", .name = name })) |item| { |
| 60 | 60 | if (std.mem.eql(u8, item, name)) { |
| 61 | 61 | return true; |
| ... | ... | @@ -64,7 +64,7 @@ pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !boo |
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | | pub fn hasColumnWithName(self: *Self, alloc: *std.mem.Allocator, comptime table: string, comptime column: string) !bool { |
| 67 | pub fn hasColumnWithName(self: *Self, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool { |
| 68 | 68 | for (try pragma.table_info(self, alloc, table)) |item| { |
| 69 | 69 | if (std.mem.eql(u8, item.name, column)) { |
| 70 | 70 | return true; |
| ... | ... | @@ -85,7 +85,7 @@ pub const Pragma = struct { |
| 85 | 85 | }; |
| 86 | 86 | |
| 87 | 87 | pub const pragma = struct { |
| 88 | | pub fn table_info(self: *Self, alloc: *std.mem.Allocator, comptime name: string) ![]const Pragma.TableInfo { |
| 88 | pub fn table_info(self: *Self, alloc: std.mem.Allocator, comptime name: string) ![]const Pragma.TableInfo { |
| 89 | 89 | return try self.collect(alloc, Pragma.TableInfo, "pragma table_info(" ++ name ++ ")", .{}); |
| 90 | 90 | } |
| 91 | 91 | }; |