Skip to content

blockblaz/lmdb-zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lmdb-zig

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.

Status

Minimum Zig: 0.15.0. Currently tracked against upstream LMDB mdb.master @ 40d3741.

Usage

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.

Layout

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)

Running tests

zig build test --summary all

Updating the vendored LMDB

See vendor/liblmdb/UPSTREAM.md.

License

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.

About

Zig bindings for LMDB (Lightning Memory-Mapped Database), vendored and ready for Zig 0.15+

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages