From 755efd3c08bbba1e66a0d9d4a6921291473994d9 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 21 Oct 2021 20:44:40 -0700 Subject: [PATCH] sqlite3- add doesTableExist --- src/sqlite3.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sqlite3.zig b/src/sqlite3.zig index 79f76d669ddad5aaef994e957918a6c7c28f0306..414fcfd9319bc7b4c7ef6506711bb91f1fa77d26 100644 --- a/src/sqlite3.zig +++ b/src/sqlite3.zig @@ -54,3 +54,12 @@ pub fn first(self: *Self, alloc: *std.mem.Allocator, comptime T: type, comptime defer stmt.deinit(); return try stmt.oneAlloc(T, alloc, .{}, args); } + +pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !bool { + for (try self.collect(alloc, string, "select name from sqlite_master where type=? AND name=?", .{ .type = "table", .name = name })) |item| { + if (std.mem.eql(u8, item, name)) { + return true; + } + } + return false; +} -- 2.54.0