Crates.io | heed |
lib.rs | heed |
version | 0.20.5 |
source | src |
created_at | 2019-10-20 19:38:42.953558 |
updated_at | 2024-08-18 17:17:32.258387 |
description | A fully typed LMDB wrapper with minimum overhead |
homepage | |
repository | https://github.com/Kerollmops/heed |
max_upload_size | |
id | 174293 |
size | 374,954 |
A Rust-centric LMDB abstraction with minimal overhead. This library enables the storage of various Rust types within LMDB, extending support to include Serde-compatible types.
Here is an example on how to store and read entries into LMDB in a safe and ACID way. For usage examples, see heed/examples/. To see more advanced usage techniques go check our Cookbook.
use std::fs;
use std::path::Path;
use heed::{EnvOpenOptions, Database};
use heed::types::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let env = unsafe { EnvOpenOptions::new().open("my-first-db")? };
// We open the default unnamed database
let mut wtxn = env.write_txn()?;
let db: Database<Str, U32<byteorder::NativeEndian>> = env.create_database(&mut wtxn, None)?;
// We open a write transaction
db.put(&mut wtxn, "seven", &7)?;
db.put(&mut wtxn, "zero", &0)?;
db.put(&mut wtxn, "five", &5)?;
db.put(&mut wtxn, "three", &3)?;
wtxn.commit()?;
// We open a read transaction to check if those values are now available
let mut rtxn = env.read_txn()?;
let ret = db.get(&rtxn, "zero")?;
assert_eq!(ret, Some(0));
let ret = db.get(&rtxn, "five")?;
assert_eq!(ret, Some(5));
Ok(())
}
You can use this command to clone the repository:
git clone --recursive https://github.com/meilisearch/heed.git
cd heed
cargo build
However, if you already cloned it and forgot to initialize the submodules, execute the following command:
git submodule update --init