authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-24 20:31:19 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-24 20:31:19 -08:00
loge5176e73203424da95a9d660648016d6f3776281
tree24e34a62aefdaba81acdde6cf04cfd303783b757
parentbfa9c50ff95f9e35c7ee3aca34bb3670ebfd73bf

update for zig 0.9.0


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

src/sqlite3.zig+6-6
......@@ -32,7 +32,7 @@ fn prepare(self: *Self, comptime query: string) !sqlite.StatementType(.{}, query
3232 };
3333}
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) ![]const T {
3636 var stmt = try self.prepare(query);
3737 defer stmt.deinit();
3838 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
4343 return list.toOwnedSlice();
4444}
4545
46pub fn exec(self: *Self, alloc: *std.mem.Allocator, comptime query: string, args: anytype) !void {
46pub fn exec(self: *Self, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void {
4747 var stmt = try self.prepare(query);
4848 defer stmt.deinit();
4949 try stmt.execAlloc(alloc, .{}, args);
5050}
5151
52pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T {
52pub fn first(self: *Self, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T {
5353 var stmt = try self.prepare(query);
5454 defer stmt.deinit();
5555 return try stmt.oneAlloc(T, alloc, .{}, args);
5656}
5757
58pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !bool {
58pub fn doesTableExist(self: *Self, alloc: std.mem.Allocator, name: string) !bool {
5959 for (try self.collect(alloc, string, "select name from sqlite_master where type=? AND name=?", .{ .type = "table", .name = name })) |item| {
6060 if (std.mem.eql(u8, item, name)) {
6161 return true;
......@@ -64,7 +64,7 @@ pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !boo
6464 return false;
6565}
6666
67pub fn hasColumnWithName(self: *Self, alloc: *std.mem.Allocator, comptime table: string, comptime column: string) !bool {
67pub fn hasColumnWithName(self: *Self, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool {
6868 for (try pragma.table_info(self, alloc, table)) |item| {
6969 if (std.mem.eql(u8, item.name, column)) {
7070 return true;
......@@ -85,7 +85,7 @@ pub const Pragma = struct {
8585};
8686
8787pub 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 {
8989 return try self.collect(alloc, Pragma.TableInfo, "pragma table_info(" ++ name ++ ")", .{});
9090 }
9191};