Fixes for passing in sqlite file name

This commit is contained in:
Nathan Anderson
2023-07-27 12:30:56 -06:00
parent cdabcf61f3
commit fb955625bc
5 changed files with 48 additions and 13 deletions
+4 -2
View File
@@ -11,9 +11,11 @@ pub const Db = struct {
_mode: ?sqlite.Db.Mode,
_sql_db: sqlite.Db,
pub fn init(allocator: Allocator, mode: ?sqlite.Db.Mode) !Db {
pub fn init(allocator: Allocator, db_path: ?[]const u8, mode: ?sqlite.Db.Mode) !Db {
const path: [:0]const u8 = if (db_path != null) try std.mem.Allocator.dupeZ(allocator, u8, db_path.?) else "./data.db";
defer allocator.free(path);
var sqlDb = try sqlite.Db.init(.{
.mode = if (mode != null) mode.? else sqlite.Db.Mode{ .File = "./data.db" },
.mode = if (mode != null) mode.? else sqlite.Db.Mode{ .File = path },
.open_flags = .{
.write = true,
.create = true,