diff --git a/src/main/db.zig b/src/main/db.zig index 6700545..a53ff8c 100644 --- a/src/main/db.zig +++ b/src/main/db.zig @@ -36,11 +36,20 @@ pub fn free(alloc: std.mem.Allocator, val: anytype) void { } } -pub fn getNote(alloc: std.mem.Allocator) !models.Note { - return try clone(alloc, models.Note{ - .content = "abcd", - }); -} +pub const Database = struct { + //internal_alloc: std.mem.Allocator, + //notes: std.StringHashMap(models.Note), + + pub fn init() Database { + return Database{}; + } + + pub fn getNote(_: *Database, alloc: std.mem.Allocator) !models.Note { + return try clone(alloc, models.Note{ + .content = "abcd", + }); + } +}; test "clone" { const T = struct { diff --git a/src/main/main.zig b/src/main/main.zig index 431adc4..3ae725b 100644 --- a/src/main/main.zig +++ b/src/main/main.zig @@ -45,7 +45,7 @@ fn respondJson(ctx: *http.server.Context, value: anytype, alloc: std.mem.Allocat } fn getNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void { - const note = try db.getNote(srv.alloc); + const note = try srv.db.getNote(srv.alloc); defer db.free(srv.alloc, note); try respondJson(ctx, note, srv.alloc); @@ -57,10 +57,12 @@ fn healthcheck(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !vo const RequestServer = struct { alloc: std.mem.Allocator, + db: db.Database, fn init(alloc: std.mem.Allocator) RequestServer { return RequestServer{ .alloc = alloc, + .db = db.Database.init(), }; }