An open API service indexing awesome lists of open source software.

https://github.com/zxcv05/lmdb-zig

Zig wrappers for lmdb
https://github.com/zxcv05/lmdb-zig

kv kv-store liblmdb lmdb wrapper zig

Last synced: about 2 months ago
JSON representation

Zig wrappers for lmdb

Awesome Lists containing this project

README

          

# lmdb zig wrapper library

## Goals
- Functional wrappers providing for every use case covered by lmdb

## Examples
see `/examples/`

### "How do I use this?"
- First, fetch the package: `zig fetch --save=lmdb git+https://github.com/zxcv05/lmdb-zig`
- Then, modify your `build.zig`:
```zig
//! build.zig

const lmdb_dep = b.dependency("lmdb", .{ .target = target, .optimize = optimize });
const lmdb_mod = lmdb_dep.module("lmdb"); // for wrappers
const lmdb_lib = lmdb_dep.artifact("lmdb"); // for linking (ignore this if you want to use system-installed library instead)

// ...

my_module.addImport("lmdb", lmdb_mod);
my_exe.linkLibrary(lmdb_lib);
// OR, to use system-installed library instead:
my_exe.linkSystemLibrary("lmdb");
```
- Finally, you can use lmdb in your project
```zig
//! my-file.zig

const lmdb = @import("lmdb");

// See `/examples/` for help with usage
pub fn my_func() !void {
const env: lmdb.Env = try .init("my-lmdb-env/", .{});
defer env.deinit();
// ...
}
```

### "Can I enable lmdb's tracing?"
As long as you're not using the system-installed library, you can freely control when tracing is enabled
- In your `build.zig`, all you need to change is the following line:
```zig
const lmdb_dep = b.dependency("lmdb", .{ .target = target, .optimize = optimize, .@"use-tracing" = true });
```

## build.zig
- zig wrappers available as module `lmdb`
- translated `liblmdb` headers available as module `c`
- compiled `liblmdb` static library available as artifact `lmdb`
- available options:
- `-Dno-install`: For default step, build but don't install `liblmdb` (default: false)
- `-Duse-tracing`: Build `liblmdb` static library with debug tracing enabled (default: false)
- `-Dno-run`: For `test` step, build but don't run unit tests (default: false)
- `-Dtest-filter='x'`: For `test` step, filter which tests are run based on `x`
- `-Dtests-use-system-lib`: For `test` step, use system installed `liblmdb` library instead of the one we build (default: false)

## todo:
- Improve error handling w/ https://github.com/ziglang/zig/pull/24381 (post 0.15.0)

# License
This project is subject to the terms of the OpenLDAP Public License v2.8 (See `LICENSE`)
Copyright 2025 lmdb-zig contributors