17 releases

new 0.21.0 Dec 6, 2024
0.20.1 Jul 2, 2024
0.20.0 Apr 26, 2024
0.20.0-alpha.9 Nov 27, 2023
0.7.0 Apr 26, 2020

#1655 in Database interfaces

Download history 12962/week @ 2024-08-18 10970/week @ 2024-08-25 12004/week @ 2024-09-01 10755/week @ 2024-09-08 9221/week @ 2024-09-15 13022/week @ 2024-09-22 11649/week @ 2024-09-29 12739/week @ 2024-10-06 15301/week @ 2024-10-13 16036/week @ 2024-10-20 15123/week @ 2024-10-27 14607/week @ 2024-11-03 10093/week @ 2024-11-10 14313/week @ 2024-11-17 15386/week @ 2024-11-24 18654/week @ 2024-12-01

59,350 downloads per month
Used in 29 crates (2 directly)

MIT license

23KB
294 lines

heed & heed3

License Crates.io Docs dependency status Build

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. It not only supports the LMDB mdb.master branch but also the mdb.master3 branch which features encryption-at-rest and checksumming.

Simple Example Usage

Here is an example on how to store and read entries into LMDB in a safe and ACID way. For usage examples, see 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(())
}

Working with two Crates: heed and heed3

The heed and heed3 crates manage a shared codebase. Within the heed3 folder, you can find the Cargo.toml specific to the heed3 crate. To facilitate work on heed3, utilize the convert-to-heed3.sh script.

This script conveniently moves the heed3/Cargo.toml file to the heed/ folder, updates the heed:: references to heed3::, and generates a commit for easy rollback if needed.

Building from Source

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

Dependencies

~82–670KB
~13K SLoC