summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.zig10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.zig b/src/main.zig
index f83f316..2d6ca46 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -15,11 +15,11 @@ const logger = std.log.scoped(.sqlite);
15/// 15///
16/// // File database 16/// // File database
17/// var db: sqlite.Db = undefined; 17/// var db: sqlite.Db = undefined;
18/// try db.init(allocator, .{ .File = "/tmp/data.db" }); 18/// try db.init(allocator, .{ .mode = { .File = "/tmp/data.db" } });
19/// 19///
20/// // In memory database 20/// // In memory database
21/// var db: sqlite.Db = undefined; 21/// var db: sqlite.Db = undefined;
22/// try db.init(allocator, .{ .Memory={} }); 22/// try db.init(allocator, .{ .mode = { .Memory = {} } });
23/// 23///
24pub const Db = struct { 24pub const Db = struct {
25 const Self = @This(); 25 const Self = @This();
@@ -34,9 +34,11 @@ pub const Db = struct {
34 }; 34 };
35 35
36 /// init creates a database with the provided `mode`. 36 /// init creates a database with the provided `mode`.
37 pub fn init(self: *Self, allocator: *mem.Allocator, mode: Mode) !void { 37 pub fn init(self: *Self, allocator: *mem.Allocator, options: anytype) !void {
38 self.allocator = allocator; 38 self.allocator = allocator;
39 39
40 const mode = if (@hasField(@TypeOf(options), "mode")) options.mode else .Memory;
41
40 switch (mode) { 42 switch (mode) {
41 .File => |path| { 43 .File => |path| {
42 logger.info("opening {}", .{path}); 44 logger.info("opening {}", .{path});
@@ -388,7 +390,7 @@ test "sqlite: statement exec" {
388 var allocator = &arena.allocator; 390 var allocator = &arena.allocator;
389 391
390 var db: Db = undefined; 392 var db: Db = undefined;
391 try db.init(testing.allocator, dbMode()); 393 try db.init(testing.allocator, .{ .mode = dbMode() });
392 394
393 // Create the tables 395 // Create the tables
394 396