From 6bfea5381bb321455adc2077d76a154cff9a1f01 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 18 Aug 2026 00:16:34 -0700 Subject: [PATCH] sqlite3: Driver does not need to be taken by pointer --- src/lib.zig | 2 +- src/sqlite3.zig | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib.zig b/src/lib.zig index 83a4af394fd37276f550030a789abe5025c7649d..a2e35c1dc0085a6160c9abaef20cd7a6f642d8d2 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -48,7 +48,7 @@ pub const Engine = union(DriverType) { pub fn collectDyn(engine: *Engine, alloc: std.mem.Allocator, comptime T: type, query: []const u8, args: anytype) ![]T { return switch (engine.*) { - .sqlite3 => |*e| { + .sqlite3 => |e| { var list = std.array_list.Managed(T).init(alloc); errdefer list.deinit(); var stmt: Driver(.sqlite3).Statement = try .prepare(e, query); diff --git a/src/sqlite3.zig b/src/sqlite3.zig index 861788079477e8820c29c76a856a806537a8dba8..3dff96dcac7f8d663ef13159a65b017f80f4039a 100644 --- a/src/sqlite3.zig +++ b/src/sqlite3.zig @@ -34,11 +34,11 @@ pub fn connect_only(allocator: std.mem.Allocator, path: [:0]const u8) !Driver { return .{ .db = db.? }; } -pub fn close(self: *Driver) void { +pub fn close(self: Driver) void { s.assert(c.sqlite3_close_v2(self.db)); } -pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]T { +pub fn collect(self: Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) ![]T { const t = tracer.trace(@src(), " {s}", .{query}); defer t.end(); @@ -53,7 +53,7 @@ pub fn collect(self: *Driver, alloc: std.mem.Allocator, comptime T: type, compti return list.toOwnedSlice(); } -pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void { +pub fn exec(self: Driver, alloc: std.mem.Allocator, comptime query: string, args: anytype) !void { const t = tracer.trace(@src(), " {s}", .{query}); defer t.end(); @@ -63,7 +63,7 @@ pub fn exec(self: *Driver, alloc: std.mem.Allocator, comptime query: string, arg try stmt.exec(alloc); } -pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { +pub fn first(self: Driver, alloc: std.mem.Allocator, comptime T: type, comptime query: string, args: anytype) !?T { const t = tracer.trace(@src(), " {s}", .{query}); defer t.end(); @@ -75,7 +75,7 @@ pub fn first(self: *Driver, alloc: std.mem.Allocator, comptime T: type, comptime return iter.step(alloc, T); } -pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bool { +pub fn doesTableExist(self: Driver, alloc: std.mem.Allocator, name: string) !bool { const t = tracer.trace(@src(), " {s}", .{name}); defer t.end(); @@ -87,7 +87,7 @@ pub fn doesTableExist(self: *Driver, alloc: std.mem.Allocator, name: string) !bo return false; } -pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool { +pub fn hasColumnWithName(self: Driver, alloc: std.mem.Allocator, comptime table: string, comptime column: string) !bool { const t = tracer.trace(@src(), " {s}.{s}", .{ table, column }); defer t.end(); @@ -99,19 +99,19 @@ pub fn hasColumnWithName(self: *Driver, alloc: std.mem.Allocator, comptime table return false; } -pub fn createTable(self: *Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void { +pub fn createTable(self: Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void { const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name }); defer t.end(); try self.exec(alloc, comptime std.fmt.comptimePrint("create table {s}({s} {s} primary key not null)", .{ name, pk_name, nameForType2(pk_type) }), .{}); } -pub fn addColumn(self: *Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void { +pub fn addColumn(self: Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void { const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); defer t.end(); try self.exec(alloc, comptime std.fmt.comptimePrint("alter table {s} add \"{s}\" {s}", .{ table_name, col_name, nameForType(T) }), .{}); } -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 { +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 { const t = tracer.trace(@src(), " {s}.{s}", .{ table_name, col_name }); defer t.end(); 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 { }; pub const pragma = struct { - pub fn table_info(self: *Driver, alloc: std.mem.Allocator, comptime name: string) ![]const Pragma.TableInfo { + pub fn table_info(self: Driver, alloc: std.mem.Allocator, comptime name: string) ![]const Pragma.TableInfo { const t = tracer.trace(@src(), " {s}", .{name}); defer t.end(); @@ -288,7 +288,7 @@ pub const Statement = struct { db: *c.sqlite3, stmt: *c.sqlite3_stmt, - pub fn prepare(driver: *Driver, query: []const u8) !Statement { + pub fn prepare(driver: Driver, query: []const u8) !Statement { var stmt: ?*c.sqlite3_stmt = null; var flags: c_uint = 0; _ = &flags; -- 2.54.0