authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:45:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 20:45:07 -07:00
logbfa9c50ff95f9e35c7ee3aca34bb3670ebfd73bf
tree45dcff2a4dc2414cc99cf156c4817f7814b57bae
parent755efd3c08bbba1e66a0d9d4a6921291473994d9

sqlite3- add hasColumnWithName


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

src/sqlite3.zig+26
......@@ -63,3 +63,29 @@ pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !boo
6363 }
6464 return false;
6565}
66
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| {
69 if (std.mem.eql(u8, item.name, column)) {
70 return true;
71 }
72 }
73 return false;
74}
75
76pub const Pragma = struct {
77 pub const TableInfo = struct {
78 cid: u16,
79 name: string,
80 type: string,
81 notnull: bool,
82 dflt_value: string,
83 pk: bool,
84 };
85};
86
87pub const pragma = struct {
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 ++ ")", .{});
90 }
91};