#lmdb #storage

smolheed

LMDB上的一层薄包装,最小化开销

1 个不稳定版本

0.1.0 2021年11月24日

#2856数据库接口

MIT 协议

165KB
2.5K SLoC

smolheed

LMDB上的一层薄包装,最小化开销。它源自heed crate,类型更严格,稍微复杂一些。

它为您提供了在LMDB中存储键/值的方法,没有任何限制,并且开销最小。

示例用法

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()[..]));

您想了解更多可能性?请查看示例

依赖项

~0.6–1.3MB
~27K SLoC