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...@@ -32,7 +32,7 @@ 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) ![]const 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);
...@@ -43,19 +43,19 @@ pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptim...@@ -43,19 +43,19 @@ pub fn collect(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptim
43 return list.toOwnedSlice();43 return list.toOwnedSlice();
44}44}
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 {
47 var stmt = try self.prepare(query);47 var stmt = try self.prepare(query);
48 defer stmt.deinit();48 defer stmt.deinit();
49 try stmt.execAlloc(alloc, .{}, args);49 try stmt.execAlloc(alloc, .{}, args);
50}50}
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 {
53 var stmt = try self.prepare(query);53 var stmt = try self.prepare(query);
54 defer stmt.deinit();54 defer stmt.deinit();
55 return try stmt.oneAlloc(T, alloc, .{}, args);55 return try stmt.oneAlloc(T, alloc, .{}, args);
56}56}
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 {
59 for (try self.collect(alloc, string, "select name from sqlite_master where type=? AND name=?", .{ .type = "table", .name = name })) |item| {59 for (try self.collect(alloc, string, "select name from sqlite_master where type=? AND name=?", .{ .type = "table", .name = name })) |item| {
60 if (std.mem.eql(u8, item, name)) {60 if (std.mem.eql(u8, item, name)) {
61 return true;61 return true;
...@@ -64,7 +64,7 @@ pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !boo...@@ -64,7 +64,7 @@ pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !boo
64 return false;64 return false;
65}65}
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 {
68 for (try pragma.table_info(self, alloc, table)) |item| {68 for (try pragma.table_info(self, alloc, table)) |item| {
69 if (std.mem.eql(u8, item.name, column)) {69 if (std.mem.eql(u8, item.name, column)) {
70 return true;70 return true;
...@@ -85,7 +85,7 @@ pub const Pragma = struct {...@@ -85,7 +85,7 @@ pub const Pragma = struct {
85};85};
8686
87pub const pragma = struct {87pub 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 return try self.collect(alloc, Pragma.TableInfo, "pragma table_info(" ++ name ++ ")", .{});89 return try self.collect(alloc, Pragma.TableInfo, "pragma table_info(" ++ name ++ ")", .{});
90 }90 }
91};91};