Skip to content

Commit

Permalink
support custom db path
Browse files Browse the repository at this point in the history
  • Loading branch information
StringNick committed Oct 7, 2024
1 parent b18daf0 commit b602693
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/mint.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ pub fn main() !void {
};
defer clap_res.deinit();

var arena = std.heap.ArenaAllocator.init(gpa.allocator());
defer arena.deinit();

const config_path = clap_res.args.config orelse "config.toml";

// TODO add work dir
Expand All @@ -101,7 +104,13 @@ pub fn main() !void {
},
inline .sqlite => v: {
// TODO custom path to database?
var db = try core.mint_memory.MintSqliteDatabase.initFrom(gpa.allocator(), "./cocomint_db.sqlite");

const path = try arena.allocator().dupeZ(u8, parsed_settings.value.sqlite.?.path);

var db = try core.mint_memory.MintSqliteDatabase.initFrom(
gpa.allocator(),
path.ptr,
);
errdefer db.deinit();

break :v try MintDatabase.initFrom(core.mint_memory.MintSqliteDatabase, gpa.allocator(), db);
Expand Down Expand Up @@ -184,9 +193,6 @@ pub fn main() !void {
ln_backends.deinit();
}

var arena = std.heap.ArenaAllocator.init(gpa.allocator());
defer arena.deinit();

// TODO set ln router
// additional routers for httpz server
switch (parsed_settings.value.ln.ln_backend) {
Expand Down
3 changes: 3 additions & 0 deletions src/mintd/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mnemonic = ""
# Database engine (sqlite/redb) defaults to sqlite
# engine = "sqlite"

[sqlite]
# path = "" default ./cocomint_sqlite.db

[ln]
# Required ln backend `cln`, `lnd`, `strike`, `fakewallet`, 'lnbits', 'phoenixd'
ln_backend = "lnbits"
Expand Down
5 changes: 5 additions & 0 deletions src/mintd/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const Settings = struct {
lnbits: ?Lnbits,
fake_wallet: ?FakeWallet,
database: Database,
sqlite: ?Sqlite = null,

pub fn initFromToml(gpa: std.mem.Allocator, config_file_name: []const u8) !zig_toml.Parsed(Settings) {
var parser = zig_toml.Parser(Settings).init(gpa);
Expand All @@ -25,6 +26,10 @@ pub const Settings = struct {
}
};

pub const Sqlite = struct {
path: []const u8 = "./cocomint_db.sqlite",
};

pub const DatabaseEngine = enum {
sqlite,
redb,
Expand Down

0 comments on commit b602693

Please sign in to comment.