authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:44:40 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:44:40 -07:00
log755efd3c08bbba1e66a0d9d4a6921291473994d9
tree000da5f926841e869ddd47d1f1db721b04ebee99
parent59c93af1e08e3b0843335710a2348b990a762b44

sqlite3- add doesTableExist


1 files changed, 9 insertions(+), 0 deletions(-)

src/sqlite3.zig+9
...@@ -54,3 +54,12 @@ pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime...@@ -54,3 +54,12 @@ pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime
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}
57
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| {
60 if (std.mem.eql(u8, item, name)) {
61 return true;
62 }
63 }
64 return false;
65}