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) {
4848
4949 pub fn collectDyn(engine: *Engine, alloc: std.mem.Allocator, comptime T: type, query: []const u8, args: anytype) ![]T {
5050 return switch (engine.*) {
51 .sqlite3 => |*e| {
51 .sqlite3 => |e| {
5252 var list = std.array_list.Managed(T).init(alloc);
5353 errdefer list.deinit();
5454 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 {
3434 return .{ .db = db.? };
3535}
3636
37pub fn close(self: *Driver) void {
37pub fn close(self: Driver) void {
3838 s.assert(c.sqlite3_close_v2(self.db));
3939}
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 {
4242 const t = tracer.trace(@src(), " {s}", .{query});
4343 defer t.end();
4444
......@@ -53,7 +53,7 @@ pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, compti
5353 return list.toOwnedSlice();
5454}
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 {
5757 const t = tracer.trace(@src(), " {s}", .{query});
5858 defer t.end();
5959
......@@ -63,7 +63,7 @@ pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, arg
6363 try stmt.exec(alloc);
6464}
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 {
6767 const t = tracer.trace(@src(), " {s}", .{query});
6868 defer t.end();
6969
......@@ -75,7 +75,7 @@ pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime
7575 return iter.step(alloc, T);
7676}
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 {
7979 const t = tracer.trace(@src(), " {s}", .{name});
8080 defer t.end();
8181
......@@ -87,7 +87,7 @@ pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bo
8787 return false;
8888}
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 {
9191 const t = tracer.trace(@src(), " {s}.{s}", .{ table, column });
9292 defer t.end();
9393
......@@ -99,19 +99,19 @@ pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table
9999 return false;
100100}
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 {
103103 const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name });
104104 defer t.end();
105105 try self.exec(alloc, comptime std.fmt.comptimePrint("create table {s}({s} {s} primary key not null)", .{ name, pk_name, nameForType2(pk_type) }), .{});
106106}
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 {
109109 const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name });
110110 defer t.end();
111111 try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s}", .{ table_name, col_name, nameForType(T) }), .{});
112112}
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 {
115115 const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name });
116116 defer t.end();
117117 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 {
184184};
185185
186186pub 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 {
188188 const t = tracer.trace(@src(), " {s}", .{name});
189189 defer t.end();
190190
......@@ -288,7 +288,7 @@ pub const Statement = struct {
288288 db: *c.sqlite3,
289289 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 {
292292 var stmt: ?*c.sqlite3_stmt = null;
293293 var flags: c_uint = 0;
294294 _ = &flags;