| ... | ... | @@ -63,3 +63,29 @@ pub fn doesTableExist(self: *Self, alloc: *std.mem.Allocator, name: string) !boo |
| 63 | 63 | } |
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | |
| 67 | pub 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 | |
| 76 | pub 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 | |
| 87 | pub 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 | }; |