summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2021-08-12 11:53:02 +0200
committerGravatar GitHub2021-08-12 11:53:02 +0200
commit4954c419d379ffbb637904b41d25ef910c6bb02b (patch)
treeb528338332a05a6db66c7c256e67c014e33fed37
parentMerge pull request #37 from vrischmann/improve-doc (diff)
parentupdate README with new init syntax as well (diff)
downloadzig-sqlite-4954c419d379ffbb637904b41d25ef910c6bb02b.tar.gz
zig-sqlite-4954c419d379ffbb637904b41d25ef910c6bb02b.tar.xz
zig-sqlite-4954c419d379ffbb637904b41d25ef910c6bb02b.zip
Merge pull request #36 from nektro/master
Various fixes
-rw-r--r--.github/workflows/main.yml2
-rw-r--r--.gitignore1
-rw-r--r--README.md3
-rw-r--r--sqlite.zig21
4 files changed, 14 insertions, 13 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index f2b5c2c..587c172 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -27,6 +27,7 @@ jobs:
27 27
28 test-in-memory: 28 test-in-memory:
29 strategy: 29 strategy:
30 fail-fast: false
30 matrix: 31 matrix:
31 os: [ubuntu-latest, windows-latest] 32 os: [ubuntu-latest, windows-latest]
32 runs-on: ${{ matrix.os }} 33 runs-on: ${{ matrix.os }}
@@ -43,6 +44,7 @@ jobs:
43 44
44 test-with-filesystem: 45 test-with-filesystem:
45 strategy: 46 strategy:
47 fail-fast: false
46 matrix: 48 matrix:
47 os: [ubuntu-latest, windows-latest] 49 os: [ubuntu-latest, windows-latest]
48 runs-on: ${{ matrix.os }} 50 runs-on: ${{ matrix.os }}
diff --git a/.gitignore b/.gitignore
index 48318b2..b31f6d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
1/build_runner.zig 1/build_runner.zig
2zig-*
diff --git a/README.md b/README.md
index 235cbc7..b57510a 100644
--- a/README.md
+++ b/README.md
@@ -111,8 +111,7 @@ const sqlite = @import("sqlite");
111You must create and initialize an instance of `sqlite.Db`: 111You must create and initialize an instance of `sqlite.Db`:
112 112
113```zig 113```zig
114var db: sqlite.Db = undefined; 114var db = try sqlite.Db.init(.{
115try db.init(.{
116 .mode = sqlite.Db.Mode{ .File = "/home/vincent/mydata.db" }, 115 .mode = sqlite.Db.Mode{ .File = "/home/vincent/mydata.db" },
117 .open_flags = .{ 116 .open_flags = .{
118 .write = true, 117 .write = true,
diff --git a/sqlite.zig b/sqlite.zig
index b5f7b72..bbf7043 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -312,7 +312,7 @@ pub const Db = struct {
312 }; 312 };
313 313
314 /// init creates a database with the provided options. 314 /// init creates a database with the provided options.
315 pub fn init(self: *Self, options: InitOptions) !void { 315 pub fn init(options: InitOptions) !Self {
316 var dummy_diags = Diagnostics{}; 316 var dummy_diags = Diagnostics{};
317 var diags = options.diags orelse &dummy_diags; 317 var diags = options.diags orelse &dummy_diags;
318 318
@@ -348,7 +348,7 @@ pub const Db = struct {
348 return errorFromResultCode(result); 348 return errorFromResultCode(result);
349 } 349 }
350 350
351 self.db = db.?; 351 return Self{ .db = db.? };
352 }, 352 },
353 .Memory => { 353 .Memory => {
354 logger.info("opening in memory", .{}); 354 logger.info("opening in memory", .{});
@@ -366,7 +366,7 @@ pub const Db = struct {
366 return errorFromResultCode(result); 366 return errorFromResultCode(result);
367 } 367 }
368 368
369 self.db = db.?; 369 return Self{ .db = db.? };
370 }, 370 },
371 } 371 }
372 } 372 }
@@ -599,7 +599,7 @@ pub fn Iterator(comptime Type: type) type {
599 }, 599 },
600 .Struct => { 600 .Struct => {
601 std.debug.assert(columns == TypeInfo.Struct.fields.len); 601 std.debug.assert(columns == TypeInfo.Struct.fields.len);
602 return try self.readStruct(.{}); 602 return try self.readStruct(options);
603 }, 603 },
604 else => @compileError("cannot read into type " ++ @typeName(Type) ++ " ; if dynamic memory allocation is required use nextAlloc"), 604 else => @compileError("cannot read into type " ++ @typeName(Type) ++ " ; if dynamic memory allocation is required use nextAlloc"),
605 } 605 }
@@ -1030,7 +1030,10 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t
1030 const StructTypeInfo = @typeInfo(StructType).Struct; 1030 const StructTypeInfo = @typeInfo(StructType).Struct;
1031 1031
1032 if (comptime query.nb_bind_markers != StructTypeInfo.fields.len) { 1032 if (comptime query.nb_bind_markers != StructTypeInfo.fields.len) {
1033 @compileError("number of bind markers not equal to number of fields"); 1033 @compileError(comptime std.fmt.comptimePrint("number of bind markers ({d}) not equal to number of fields ({d})", .{
1034 query.nb_bind_markers,
1035 StructTypeInfo.fields.len,
1036 }));
1034 } 1037 }
1035 1038
1036 inline for (StructTypeInfo.fields) |struct_field, _i| { 1039 inline for (StructTypeInfo.fields) |struct_field, _i| {
@@ -1915,8 +1918,7 @@ test "sqlite: blob open, reopen" {
1915test "sqlite: failing open" { 1918test "sqlite: failing open" {
1916 var diags: Diagnostics = undefined; 1919 var diags: Diagnostics = undefined;
1917 1920
1918 var db: Db = undefined; 1921 const res = Db.init(.{
1919 const res = db.init(.{
1920 .diags = &diags, 1922 .diags = &diags,
1921 .open_flags = .{}, 1923 .open_flags = .{},
1922 .mode = .{ .File = "/tmp/not_existing.db" }, 1924 .mode = .{ .File = "/tmp/not_existing.db" },
@@ -2010,16 +2012,13 @@ fn getTestDb() !Db {
2010 2012
2011 var mode = dbMode(&fba.allocator); 2013 var mode = dbMode(&fba.allocator);
2012 2014
2013 var db: Db = undefined; 2015 return try Db.init(.{
2014 try db.init(.{
2015 .open_flags = .{ 2016 .open_flags = .{
2016 .write = true, 2017 .write = true,
2017 .create = true, 2018 .create = true,
2018 }, 2019 },
2019 .mode = mode, 2020 .mode = mode,
2020 }); 2021 });
2021
2022 return db;
2023} 2022}
2024 2023
2025fn tmpDbPath(allocator: *mem.Allocator) ![:0]const u8 { 2024fn tmpDbPath(allocator: *mem.Allocator) ![:0]const u8 {