Fixes for passing in sqlite file name
This commit is contained in:
+33
-4
@@ -14,18 +14,47 @@ const note = @import("routes/shared_note.zig");
|
||||
|
||||
const Db = @import("db/db.zig").Db;
|
||||
|
||||
var db: Db = undefined;
|
||||
var db: ?Db = null;
|
||||
|
||||
pub fn getDb() *Db {
|
||||
return &db;
|
||||
return &db.?;
|
||||
}
|
||||
|
||||
pub fn startHttpServer() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
db = try Db.init(allocator, null);
|
||||
defer db.deinit();
|
||||
// db = try Db.init(allocator, null);
|
||||
// defer db.deinit();
|
||||
var args = try std.process.argsWithAllocator(allocator);
|
||||
|
||||
// skip program name
|
||||
_ = args.skip();
|
||||
while (args.next()) |arg| {
|
||||
if (std.mem.eql(u8, arg, "--db_path")) {
|
||||
const path = args.next();
|
||||
// std.debug.print("Got path: {any}", .{path});
|
||||
if (path) |db_path| {
|
||||
db = try Db.init(allocator, db_path, null);
|
||||
} else {
|
||||
std.log.err("Db path not provided after arg", .{});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (std.mem.eql(u8, arg, "--make-migration")) {
|
||||
if (db == null) {
|
||||
std.log.err("Cannot migrate, provide db path first", .{});
|
||||
return;
|
||||
}
|
||||
try db.?.wipeAndMigrateDb();
|
||||
}
|
||||
}
|
||||
|
||||
if (db == null) {
|
||||
db = try Db.init(allocator, null, null);
|
||||
}
|
||||
|
||||
defer db.?.deinit();
|
||||
|
||||
var server = try httpz.Server().init(allocator, .{ .port = 8081 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user