Zig bindings for LMDB (Lightning Memory-Mapped Database), targeting Zig 0.15+.
The liblmdb C sources are vendored, so the only build-time requirement
is Zig itself — no system liblmdb or pkg-config lookups.
Minimum Zig: 0.15.0. Currently tracked against upstream LMDB mdb.master @ 40d3741.
Add the package to your build.zig.zon:
.dependencies = .{
.lmdb = .{
.url = "git+https://github.com/blockblaz/lmdb-zig#<commit-sha>",
.hash = "<zig-will-print-this-on-first-build>",
},
},Wire it into your build.zig:
const lmdb_dep = b.dependency("lmdb", .{
.target = target,
.optimize = optimize,
});
my_module.addImport("lmdb", lmdb_dep.module("lmdb"));Then use it from Zig:
const lmdb = @import("lmdb");
var env = try lmdb.Env.open(allocator, "./data", .{
.map_size = 1 << 30, // 1 GiB address space
.max_dbs = 4,
});
defer env.deinit();
var txn = try env.beginTxn(false); // read-write
errdefer txn.abort();
const dbi = try txn.openDbi("blocks", .{ .create = true });
try txn.put(dbi, "key", "value", .{});
try txn.commit();See src/lmdb.zig for the full API.
build.zig # exposes a single `lmdb` module
build.zig.zon
src/
c.zig # @cImport("lmdb.h")
lmdb.zig # Zig wrapper (Env, Txn, Dbi, Cursor, errors)
vendor/liblmdb/ # upstream C sources (see vendor/liblmdb/UPSTREAM.md)
zig build test --summary allSee vendor/liblmdb/UPSTREAM.md.
The Zig wrapper (everything under src/ and build.zig) is MIT — see
LICENSE.
The vendored C sources under vendor/liblmdb/ are distributed under
the OpenLDAP Public License v2.8 — see vendor/liblmdb/LICENSE
and NOTICE.