From 4792723ff4fcb37769c040eb3eaafb16496ad829 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 9 Aug 2021 01:16:51 -0700 Subject: make `init` return a Self instead of updating a pointer --- sqlite.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index b0f3216..498f83d 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -303,7 +303,7 @@ pub const Db = struct { }; /// init creates a database with the provided options. - pub fn init(self: *Self, options: InitOptions) !void { + pub fn init(options: InitOptions) !Self { var dummy_diags = Diagnostics{}; var diags = options.diags orelse &dummy_diags; @@ -339,7 +339,7 @@ pub const Db = struct { return errorFromResultCode(result); } - self.db = db.?; + return Self{ .db = db.? }; }, .Memory => { logger.info("opening in memory", .{}); @@ -357,7 +357,7 @@ pub const Db = struct { return errorFromResultCode(result); } - self.db = db.?; + return Self{ .db = db.? }; }, } } -- cgit v1.2.3 From c48ce60993a0b3e26f3f1f0af1e325270f937270 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 9 Aug 2021 01:17:29 -0700 Subject: iterator- pass along options object --- sqlite.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index 498f83d..346b172 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -565,7 +565,7 @@ pub fn Iterator(comptime Type: type) type { }, .Struct => { std.debug.assert(columns == TypeInfo.Struct.fields.len); - return try self.readStruct(.{}); + return try self.readStruct(options); }, else => @compileError("cannot read into type " ++ @typeName(Type) ++ " ; if dynamic memory allocation is required use nextAlloc"), } -- cgit v1.2.3 From fc3d68e1764600cf508cc9ebc35b7b84140ef4ee Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 9 Aug 2021 01:17:49 -0700 Subject: options asks for `allocator` field but its not there --- sqlite.zig | 1 + 1 file changed, 1 insertion(+) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index 346b172..e8b3980 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -492,6 +492,7 @@ pub const Db = struct { pub const QueryOptions = struct { /// if provided, diags will be populated in case of failures. diags: ?*Diagnostics = null, + allocator: *std.mem.Allocator = undefined, }; /// Iterator allows iterating over a result set. -- cgit v1.2.3 From 1e203086c5be85a3a77e630b1844ea39115d8276 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 9 Aug 2021 01:18:22 -0700 Subject: clarify bind marker len compile error --- sqlite.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index e8b3980..7ba64ba 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -997,7 +997,10 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t const StructTypeInfo = @typeInfo(StructType).Struct; if (comptime query.nb_bind_markers != StructTypeInfo.fields.len) { - @compileError("number of bind markers not equal to number of fields"); + @compileError(comptime std.fmt.comptimePrint("number of bind markers ({d}) not equal to number of fields ({d})", .{ + query.nb_bind_markers, + StructTypeInfo.fields.len, + })); } inline for (StructTypeInfo.fields) |struct_field, _i| { -- cgit v1.2.3 From 3f3b607d705a3e0871a030946b62c402ee20de0c Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 11 Aug 2021 22:32:06 -0700 Subject: adding allocator to Db.QueryOptions was a mistake --- sqlite.zig | 1 - 1 file changed, 1 deletion(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index 7ba64ba..2061739 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -492,7 +492,6 @@ pub const Db = struct { pub const QueryOptions = struct { /// if provided, diags will be populated in case of failures. diags: ?*Diagnostics = null, - allocator: *std.mem.Allocator = undefined, }; /// Iterator allows iterating over a result set. -- cgit v1.2.3 From ea6bdc66a18d97ef8e923c810d4e6d52accce5ca Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 11 Aug 2021 22:33:02 -0700 Subject: update tests for new use of `Db.init` --- sqlite.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index 2061739..65c293e 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -1884,8 +1884,7 @@ test "sqlite: blob open, reopen" { test "sqlite: failing open" { var diags: Diagnostics = undefined; - var db: Db = undefined; - const res = db.init(.{ + const res = Db.init(.{ .diags = &diags, .open_flags = .{}, .mode = .{ .File = "/tmp/not_existing.db" }, @@ -1979,16 +1978,13 @@ fn getTestDb() !Db { var mode = dbMode(&fba.allocator); - var db: Db = undefined; - try db.init(.{ + return try Db.init(.{ .open_flags = .{ .write = true, .create = true, }, .mode = mode, }); - - return db; } fn tmpDbPath(allocator: *mem.Allocator) ![:0]const u8 { -- cgit v1.2.3