https://github.com/meilisearch/heed
A fully typed LMDB wrapper with minimum overhead 🐦
https://github.com/meilisearch/heed
key-value-store lmdb memory-mapping typed wrapper
Last synced: 9 days ago
JSON representation
A fully typed LMDB wrapper with minimum overhead 🐦
- Host: GitHub
- URL: https://github.com/meilisearch/heed
- Owner: meilisearch
- License: mit
- Created: 2019-10-04T16:25:17.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-16T15:20:37.000Z (6 months ago)
- Last Synced: 2024-11-16T16:27:01.415Z (6 months ago)
- Topics: key-value-store, lmdb, memory-mapping, typed, wrapper
- Language: Rust
- Homepage: https://docs.rs/heed
- Size: 3.25 MB
- Stars: 621
- Watchers: 16
- Forks: 55
- Open Issues: 36
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
heed & heed3
[](#LICENSE)
[](https://crates.io/crates/heed)
[](https://docs.rs/heed)
[](https://deps.rs/repo/github/meilisearch/heed)
[](https://github.com/meilisearch/heed/actions/workflows/rust.yml)
[](https://discord.com/channels/1006923006964154428/1347203493106024528)Rust-centric [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) abstractions with minimal overhead. These libraries enable the storage of various Rust types within LMDB, extending support to include Serde-compatible types. It supports not only the LMDB `mdb.master` branch but also the `mdb.master3` branch, which features encryption-at-rest.
## 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/](examples/). To see more advanced usage techniques go check our [Cookbook](https://docs.rs/heed/latest/heed/cookbook/index.html).
```rust
use std::fs;
use std::path::Path;
use heed::{EnvOpenOptions, Database};
use heed::types::*;fn main() -> Result<(), Box> {
let env = unsafe { EnvOpenOptions::new().open("my-first-db")? };// We open the default unnamed database
let mut wtxn = env.write_txn()?;
let db: Database> = 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:
```bash
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:
```bash
git submodule update --init
```