Embedded key-value storage with an LSM-tree index, a separate value log, and write-ahead logging for recovery.
Requires Zig 0.14.1.
zig fetch --save "git+https://github.com/lovez-dev/wiskdb#main"Add the module to your executable in build.zig:
const dep = b.dependency("wiskdb", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("wiskdb", dep.module("wiskdb"));const std = @import("std");
const wiskdb = @import("wiskdb");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var db = try wiskdb.openPath(
allocator,
.{},
"data",
.{
.create_if_missing = true,
.db = .{ .durability = .sync },
},
);
defer db.deinit();
try db.put("hello", "world");
if (try db.get("hello")) |value| {
defer allocator.free(value);
std.debug.print("{s}\n", .{value});
}
try db.delete("hello");
try db.close();
}get returns owned memory; free it with the same allocator. getInto uses a caller-owned buffer; its returned slice borrows that buffer and must not be freed separately. Call close() to observe persistence errors, and keep the deferred deinit() for cleanup on early returns.
Durability modes are .sync, .interval (the default), and .@"async". The example uses synchronous commits.
Cleanup failures are silent by default. Set Io.diagnostics to receive filenames and errors
without replacing the main operation result. The callback is synchronous, may run on
background threads while locks are held, and must not call database operations. Its context
must outlive the database; filenames are borrowed only until the callback returns.
zig build examples
./zig-out/bin/wiskdb-basicThe examples cover basic operations, atomic batches, reopening a database, collections, and crash recovery.
zig build fmt
zig build test
zig build test -Doptimize=ReleaseSafeRun tests whose names contain a substring with the same build entry point:
zig build test -Dtest-filter="recovery:"
zig build test -Dtest-filter="memory stats exclude caller results and drain on close"