authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-18 00:16:34-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-18 00:16:34-07:00
log6bfea5381bb321455adc2077d76a154cff9a1f01
tree341aacd53dd679fc373fb71aff5d0320d53c8203
parentea2700127eb26ee9cef2bc5dac091494ef2fcfe5
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

sqlite3: Driver does not need to be taken by pointer


2 files changed, 12 insertions(+), 12 deletions(-)

src/lib.zig+1-1
...@@ -48,7 +48,7 @@ pub const Engine = union(DriverType) {...@@ -48,7 +48,7 @@ pub const Engine = union(DriverType) {
4848
49 pub fn collectDyn(engine: *Engine, alloc: std.mem.Allocator, comptime T: type, query: []const u8, args: anytype) ![]T {49 pub fn collectDyn(engine: *Engine, alloc: std.mem.Allocator, comptime T: type, query: []const u8, args: anytype) ![]T {
50 return switch (engine.*) {50 return switch (engine.*) {
51 .sqlite3 => |*e| {51 .sqlite3 => |e| {
52 var list = std.array_list.Managed(T).init(alloc);52 var list = std.array_list.Managed(T).init(alloc);
53 errdefer list.deinit();53 errdefer list.deinit();
54 var stmt: Driver(.sqlite3).Statement = try .prepare(e, query);54 var stmt: Driver(.sqlite3).Statement = try .prepare(e, query);
src/sqlite3.zig+11-11
...@@ -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}
3636
37pub fn close(self: *Driver) void {37pub 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}
4040
41pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]T {41pub 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();
4444
...@@ -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}
5555
56pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void {56pub 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();
5959
...@@ -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}
6565
66pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T {66pub 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();
6969
...@@ -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}
7777
78pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bool {78pub 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();
8181
...@@ -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}
8989
90pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool {90pub 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();
9393
...@@ -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}
101101
102pub fn createTable(self: *Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void {102pub 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}
107107
108pub fn addColumn(self: *Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void {108pub 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}
113113
114pub 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 {114pub 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};
185185
186pub const pragma = struct {186pub 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();
190190
...@@ -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,
290290
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;