Typed key-value storage with multiple backends for AIngle
A simple, humane, typed key-value storage solution for Rust. This crate supports multiple backend engines with varying guarantees, optimized for use within the AIngle distributed systems framework.
- Multiple backends - LMDB for performance, SafeMode for reliability
- Type-safe API - Strongly typed keys and values
- Concurrent access - Multi-reader, single-writer transactions
- Crash-safe - ACID-compliant storage with durability guarantees
- Compact - Efficient memory-mapped I/O
[dependencies]
aingle-rkv = "0.1"use rkv::{Manager, Rkv, StoreOptions, Value};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open or create the environment
let path = Path::new("./my-store");
let mut manager = Manager::singleton().write()?;
let env = manager.get_or_create(path, Rkv::new)?;
// Open a store
let store = env.read()?.open_single("mystore", StoreOptions::create())?;
// Write data
{
let mut writer = env.read()?.write()?;
store.put(&mut writer, "key", &Value::Str("value"))?;
writer.commit()?;
}
// Read data
let reader = env.read()?.read()?;
let value = store.get(&reader, "key")?;
println!("Value: {:?}", value);
Ok(())
}| Backend | Use Case | Characteristics |
|---|---|---|
| LMDB | High performance | Memory-mapped, fast reads |
| SafeMode | Reliability | In-memory with sync writes |
| SQLite | Portability | Planned for future release |
For production environments requiring maximum reliability:
use rkv::{Manager, Rkv};
use rkv::backend::{SafeMode, SafeModeEnvironment};
let mut manager = Manager::<SafeModeEnvironment>::singleton().write()?;
let env = manager.get_or_create(path, Rkv::new::<SafeMode>)?;| Feature | Description | Default |
|---|---|---|
db-dup-sort |
Multiple values per key | Yes |
db-int-key |
Integer key optimizations | Yes |
backtrace |
Error backtraces | No |
# Build
cargo build
# Run tests
cargo test
# Generate documentation
cargo doc --open
# Run examples
./run-all-examples.shThis crate is part of the AIngle ecosystem - a Semantic DAG framework for IoT and distributed AI applications.
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Maintained by Apilium Technologies - Tallinn, Estonia