| Crates.io | snaildb |
| lib.rs | snaildb |
| version | 0.2.2 |
| created_at | 2025-12-21 15:35:57.036172+00 |
| updated_at | 2026-01-01 16:18:25.410841+00 |
| description | An embedded, persistent key-value store with high write throughput and durability |
| homepage | https://github.com/Hk669/snaildb |
| repository | https://github.com/Hk669/snaildb |
| max_upload_size | |
| id | 1998143 |
| size | 85,288 |
An embedded, persistent key-value store written in Rust.
Add to your Cargo.toml:
[dependencies]
snaildb = "0.2"
Or install the binaries from GitHub Releases.
use snaildb::SnailDb;
use anyhow::Result;
fn main() -> Result<()> {
// Open or create a database at a directory
let mut db = SnailDb::open("./data")?;
// Store a key-value pair
db.put("user:1", b"Alice")?;
db.put("user:2", b"Bob")?;
// Retrieve a value
match db.get("user:1")? {
Some(value) => println!("Found: {:?}", String::from_utf8_lossy(&value)),
None => println!("Key not found"),
}
// Delete a key
db.delete("user:2")?;
Ok(())
}
use snaildb::SnailDb;
let mut db = SnailDb::open("./data")?
.with_flush_threshold(256 * 1024 * 1024); // Flush memtable after 256 MiB
let mut db = SnailDb::open("./data")?;
// Store string values
db.put("name", "snaildb")?;
// Retrieve as string
if let Some(bytes) = db.get("name")? {
let value = String::from_utf8_lossy(&bytes);
println!("Name: {}", value);
}
use snaildb::SnailDb;
use anyhow::{Result, Context};
fn store_data() -> Result<()> {
let mut db = SnailDb::open("./data")
.context("Failed to open database")?;
db.put("key", "value")
.context("Failed to store key-value pair")?;
Ok(())
}
See the examples directory for more detailed usage examples. Run them with:
cargo run --example <example_name> --package snaildb
The flush threshold determines when the in-memory memtable is flushed to disk as an SSTable. Default is 64 MiB.
let mut db = SnailDb::open("./data")?
.with_flush_threshold(256 * 1024 * 1024); // Custom threshold
snailDB uses an LSM-tree (Log-Structured Merge-tree) architecture:
Current work in progress:
Licensed under the Apache License, Version 2.0. See LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.