| ... | @@ -34,11 +34,11 @@ pub fn connect_only(allocator: std.mem.Allocator, path: [:0]const u8) !Driver { | ... | @@ -34,11 +34,11 @@ pub fn connect_only(allocator: std.mem.Allocator, path: [:0]const u8) !Driver { |
| 34 | return .{ .db = db.? }; | 34 | return .{ .db = db.? }; |
| 35 | } | 35 | } |
| 36 | | 36 | |
| 37 | pub fn close(self: *Driver) void { | 37 | pub fn close(self: Driver) void { |
| 38 | s.assert(c.sqlite3_close_v2(self.db)); | 38 | s.assert(c.sqlite3_close_v2(self.db)); |
| 39 | } | 39 | } |
| 40 | | 40 | |
| 41 | pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]T { | 41 | pub fn collect(self: Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]T { |
| 42 | const t = tracer.trace(@src(), " {s}", .{query}); | 42 | const t = tracer.trace(@src(), " {s}", .{query}); |
| 43 | defer t.end(); | 43 | defer t.end(); |
| 44 | | 44 | |
| ... | @@ -53,7 +53,7 @@ pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, compti | ... | @@ -53,7 +53,7 @@ pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, compti |
| 53 | return list.toOwnedSlice(); | 53 | return list.toOwnedSlice(); |
| 54 | } | 54 | } |
| 55 | | 55 | |
| 56 | pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void { | 56 | pub fn exec(self: Driver, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void { |
| 57 | const t = tracer.trace(@src(), " {s}", .{query}); | 57 | const t = tracer.trace(@src(), " {s}", .{query}); |
| 58 | defer t.end(); | 58 | defer t.end(); |
| 59 | | 59 | |
| ... | @@ -63,7 +63,7 @@ pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, arg | ... | @@ -63,7 +63,7 @@ pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, arg |
| 63 | try stmt.exec(alloc); | 63 | try stmt.exec(alloc); |
| 64 | } | 64 | } |
| 65 | | 65 | |
| 66 | pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { | 66 | pub fn first(self: Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { |
| 67 | const t = tracer.trace(@src(), " {s}", .{query}); | 67 | const t = tracer.trace(@src(), " {s}", .{query}); |
| 68 | defer t.end(); | 68 | defer t.end(); |
| 69 | | 69 | |
| ... | @@ -75,7 +75,7 @@ pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime | ... | @@ -75,7 +75,7 @@ pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime |
| 75 | return iter.step(alloc, T); | 75 | return iter.step(alloc, T); |
| 76 | } | 76 | } |
| 77 | | 77 | |
| 78 | pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bool { | 78 | pub fn doesTableExist(self: Driver, alloc: std.mem.Allocator, name: string) !bool { |
| 79 | const t = tracer.trace(@src(), " {s}", .{name}); | 79 | const t = tracer.trace(@src(), " {s}", .{name}); |
| 80 | defer t.end(); | 80 | defer t.end(); |
| 81 | | 81 | |
| ... | @@ -87,7 +87,7 @@ pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bo | ... | @@ -87,7 +87,7 @@ pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bo |
| 87 | return false; | 87 | return false; |
| 88 | } | 88 | } |
| 89 | | 89 | |
| 90 | pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool { | 90 | pub fn hasColumnWithName(self: Driver, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool { |
| 91 | const t = tracer.trace(@src(), " {s}.{s}", .{ table, column }); | 91 | const t = tracer.trace(@src(), " {s}.{s}", .{ table, column }); |
| 92 | defer t.end(); | 92 | defer t.end(); |
| 93 | | 93 | |
| ... | @@ -99,19 +99,19 @@ pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table | ... | @@ -99,19 +99,19 @@ pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table |
| 99 | return false; | 99 | return false; |
| 100 | } | 100 | } |
| 101 | | 101 | |
| 102 | pub fn createTable(self: *Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void { | 102 | pub fn createTable(self: Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void { |
| 103 | const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name }); | 103 | const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name }); |
| 104 | defer t.end(); | 104 | defer t.end(); |
| 105 | try self.exec(alloc, comptime std.fmt.comptimePrint("create table {s}({s} {s} primary key not null)", .{ name, pk_name, nameForType2(pk_type) }), .{}); | 105 | try self.exec(alloc, comptime std.fmt.comptimePrint("create table {s}({s} {s} primary key not null)", .{ name, pk_name, nameForType2(pk_type) }), .{}); |
| 106 | } | 106 | } |
| 107 | | 107 | |
| 108 | pub fn addColumn(self: *Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void { | 108 | pub fn addColumn(self: Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void { |
| 109 | const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); | 109 | const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); |
| 110 | defer t.end(); | 110 | defer t.end(); |
| 111 | try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s}", .{ table_name, col_name, nameForType(T) }), .{}); | 111 | try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s}", .{ table_name, col_name, nameForType(T) }), .{}); |
| 112 | } | 112 | } |
| 113 | | 113 | |
| 114 | pub fn addColumnForeign(self: *Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type, comptime table_name2: []const u8, comptime col_name2: []const u8) !void { | 114 | pub fn addColumnForeign(self: Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type, comptime table_name2: []const u8, comptime col_name2: []const u8) !void { |
| 115 | const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); | 115 | const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); |
| 116 | defer t.end(); | 116 | defer t.end(); |
| 117 | try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s} references \"{s}\" (\"{s}\")", .{ table_name, col_name, nameForType(T), table_name2, col_name2 }), .{}); | 117 | try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s} references \"{s}\" (\"{s}\")", .{ table_name, col_name, nameForType(T), table_name2, col_name2 }), .{}); |
| ... | @@ -184,7 +184,7 @@ pub const Pragma = struct { | ... | @@ -184,7 +184,7 @@ pub const Pragma = struct { |
| 184 | }; | 184 | }; |
| 185 | | 185 | |
| 186 | pub const pragma = struct { | 186 | pub const pragma = struct { |
| 187 | pub fn table_info(self: *Driver, alloc: std.mem.Allocator, comptime name: string) ![]const Pragma.TableInfo { | 187 | pub fn table_info(self: Driver, alloc: std.mem.Allocator, comptime name: string) ![]const Pragma.TableInfo { |
| 188 | const t = tracer.trace(@src(), " {s}", .{name}); | 188 | const t = tracer.trace(@src(), " {s}", .{name}); |
| 189 | defer t.end(); | 189 | defer t.end(); |
| 190 | | 190 | |
| ... | @@ -288,7 +288,7 @@ pub const Statement = struct { | ... | @@ -288,7 +288,7 @@ pub const Statement = struct { |
| 288 | db: *c.sqlite3, | 288 | db: *c.sqlite3, |
| 289 | stmt: *c.sqlite3_stmt, | 289 | stmt: *c.sqlite3_stmt, |
| 290 | | 290 | |
| 291 | pub fn prepare(driver: *Driver, query: []const u8) !Statement { | 291 | pub fn prepare(driver: Driver, query: []const u8) !Statement { |
| 292 | var stmt: ?*c.sqlite3_stmt = null; | 292 | var stmt: ?*c.sqlite3_stmt = null; |
| 293 | var flags: c_uint = 0; | 293 | var flags: c_uint = 0; |
| 294 | _ = &flags; | 294 | _ = &flags; |