A lightweight embedded key-value store for Rust.
ShorterDB is an embedded key-value database designed for simplicity and ease of use. It's built for learning, experimentation, and lightweight applications that need persistent storage without the overhead of a full database server.
use shorterdb::ShorterDB;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut db = ShorterDB::new(Path::new("./my_db"))?;
db.set(b"user:1", b"alice")?;
db.set(b"user:2", b"bob")?;
if let Some(value) = db.get(b"user:1")? {
println!("Found: {}", String::from_utf8_lossy(&value));
}
db.delete(b"user:1")?;
Ok(())
}- Zero configuration — Just create a database and start using it
- Embedded — No separate server process, runs in your application
- Persistent — Data is durably stored with Write-Ahead Logging
- Fast reads — In-memory caching with automatic background flushing
- Simple API — Only
get,set, anddeleteoperations - gRPC support — Optional remote access via
shorterdb-grpccrate
Add this to your Cargo.toml:
[dependencies]
shorterDB = "0.2.0"This project is organized as a Cargo workspace:
shorterdb/
├── crates/
│ ├── shorterdb/ # Core database engine (minimal dependencies)
│ └── shorterdb-grpc/ # gRPC server (optional networking)
└── examples/ # Usage examples
# Build just the core engine (fast, minimal deps)
cargo build -p shorterdb
# Build the gRPC server
cargo build -p shorterdb-grpc
# Build everything
cargo build --workspace
# Run tests
cargo test --workspace# Using cargo
cargo run -p shorterdb-grpc
# Using Docker
docker build -t shorterdb-grpc .
docker run -p 50051:50051 shorterdb-grpcCheck out the examples/ directory:
Run an example:
cargo run -p shorterdb --example embedded
cargo run -p shorterdb --example replView the full API documentation on docs.rs
Contributions are welcome! Please feel free to submit a Pull Request.