const std = @import("std"); const zqlite = @import("zqlite"); const mod = @import("root.zig"); const log = std.log.scoped(.@"space db"); pub const DB = struct { pool: *zqlite.Pool, pub fn open(allocator: std.mem.Allocator, config: mod.config.DBConfig) !DB { log.debug("Creating DB Pool size={} path={s}", .{ config.pool_size, config.path }); const path = try allocator.dupeZ(u8, config.path); defer allocator.free(path); const pool = try zqlite.Pool.init(allocator, .{ .path = path, .size = config.pool_size, .on_first_connection = &DB.onFirstConnection, }); return .{ .pool = pool }; } pub fn deinit(this: *DB) void { this.pool.deinit(); } fn onFirstConnection(_: zqlite.Conn, _: ?*anyopaque) !void { log.info("Connected to database", .{}); } };