37 releases

new 0.20.1 May 16, 2024
0.20.0-alpha.9 Nov 27, 2023
0.20.0-alpha.3 Jul 13, 2023
0.20.0-alpha.0 Jan 11, 2023
0.6.0 Nov 26, 2019

#33 in Database interfaces

Download history 6298/week @ 2024-01-27 4021/week @ 2024-02-03 6689/week @ 2024-02-10 6937/week @ 2024-02-17 7213/week @ 2024-02-24 7776/week @ 2024-03-02 9361/week @ 2024-03-09 8739/week @ 2024-03-16 8818/week @ 2024-03-23 8519/week @ 2024-03-30 8983/week @ 2024-04-06 9642/week @ 2024-04-13 14687/week @ 2024-04-20 19793/week @ 2024-04-27 16559/week @ 2024-05-04 16179/week @ 2024-05-11

69,025 downloads per month
Used in 13 crates (8 directly)

MIT license

1MB
17K SLoC

C 11K SLoC // 0.2% comments Rust 5.5K SLoC // 0.0% comments

heed

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.

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 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(())
}

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

~0.8–2.5MB
~52K SLoC