Crates.io | smolheed |
lib.rs | smolheed |
version | 0.1.0 |
source | src |
created_at | 2021-11-24 15:28:31.30934 |
updated_at | 2021-11-24 15:28:31.30934 |
description | A thin wrapped on top of LMDB with minimum overhead |
homepage | |
repository | https://github.com/Kerollmops/smolheed |
max_upload_size | |
id | 486879 |
size | 177,165 |
A thin wrapped on top of LMDB with minimum overhead. It is derived from the heed crate which is more typed and a little bit more complex.
It provides you a way to store key/values in LMDB without any limit and with a minimal overhead.
fs::create_dir_all("target/heed.mdb")?;
let env = EnvOpenOptions::new().open("target/heed.mdb")?;
// We open the default unamed database.
// Specifying the type of the newly created database.
// Here we specify that the key is an str and the value a simple integer.
let db = env.create_database(None)?;
// We then open a write transaction and start writing into the database.
// All of those puts are type checked at compile time,
// therefore you cannot write an integer instead of a string.
let mut wtxn = env.write_txn()?;
db.put(&mut wtxn, "seven", 7_i32.to_be_bytes())?;
db.put(&mut wtxn, "zero", 0_i32.to_be_bytes())?;
db.put(&mut wtxn, "five", 5_i32.to_be_bytes())?;
db.put(&mut wtxn, "three", 3_i32.to_be_bytes())?;
wtxn.commit()?;
// We open a read transaction to check if those values are available.
// When we read we also type check at compile time.
let rtxn = env.read_txn()?;
let ret = db.get(&rtxn, "zero")?;
assert_eq!(ret, Some(&0_i32.to_be_bytes()[..]));
let ret = db.get(&rtxn, "five")?;
assert_eq!(ret, Some(&5.to_be_bytes()[..]));
You want to see more about all the possibilities? Go check out the examples.