lmdb
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | database ffi |
| Keywords | lmdb database key-value embedded |
LMDB embedded key-value store bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_lmdb.c | C FFI wrapper |
c/kit_lmdb.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/lmdb.kit | Kit LMDB - Lightning Memory-Mapped Database bindings |
tests/lmdb.test.kit | Tests for lmdb |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-lmdb.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install lmdb |
| Ubuntu | sudo apt install liblmdb-dev |
| Fedora | sudo dnf install lmdb-devel |
Usage
import Kit.LMDB as Lmdb
main = fn =>
println ("LMDB version: " ++ Lmdb.version())
match Lmdb.open "/tmp/my-database"
| Ok db ->
# Store values
Lmdb.put db "name" "Kit"
Lmdb.put db "version" "0.1.0"
# Read values
match Lmdb.get db "name"
| Some val -> println ("name: " ++ val)
| None -> println "name: not found"
# Check key existence
if Lmdb.has-key? db "name" then
println "'name' exists"
# Count entries
println ("Entries: " ++ (show (Lmdb.count db)))
# Update a value
Lmdb.put db "version" "0.2.0"
# Delete a key
Lmdb.delete db "version"
Lmdb.close db
| Err e -> println ("Error: " ++ e)
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/lmdb/, making it available for import as Kit.LMDB in other projects.
License
This package is released under the MIT License - see LICENSE for details.
LMDB is released under the OpenLDAP Public License.
Exported Functions & Types
open
Open an LMDB database environment.
Creates the directory if it doesn't exist. Uses a default map size of 10 MB (sufficient for most use cases; increase for larger databases).
Parameters:
Returns:
String -> Result Ptr String
match open "/tmp/mydb"
| Ok db ->
# ... use database ...
close db
| Err e -> println "Error: ${e}"open-with-size
Open an LMDB database with a custom map size.
Parameters:
Returns:
String -> Int -> Result Ptr String
# Open with 1 GB map size
match open-with-size "/tmp/largedb" 1073741824
| Ok db ->
# ... use database ...
close db
| Err e -> println "Error: ${e}"close
Close the database and release resources.
Parameters:
Ptr -> Unit
close dbput
Store a key-value pair in the database.
If the key already exists, its value is overwritten.
Parameters:
Returns:
Ptr -> String -> String -> Result Unit String
match put db "user:1" "Alice"
| Ok _ -> println "Stored!"
| Err e -> println "Error: ${e}"get
Get a value by key from the database.
Parameters:
Returns:
Ptr -> String -> Option String
match get db "user:1"
| Some val -> println ("Found: " ++ val)
| None -> println "Not found"delete
Delete a key from the database.
Parameters:
Returns:
Ptr -> String -> Result Unit String
match delete db "user:1"
| Ok _ -> println "Deleted!"
| Err e -> println "Error: ${e}"has-key?
Check if a key exists in the database.
Parameters:
Returns:
Ptr -> String -> Bool
if has-key? db "user:1" then
println "Key exists"list-keys
List all keys in the database.
Parameters:
Returns:
Ptr -> [String]
keys = list-keys db
List.map (fn(k) => println k) keyscount
Count the number of entries in the database.
Parameters:
Returns:
Ptr -> Int
println ("Entries: " ++ (show (count db)))version
Get the LMDB library version as a string.
Returns:
String
println ("LMDB: " ++ version())