| Crates.io | rustlite |
| lib.rs | rustlite |
| version | 0.8.0 |
| created_at | 2025-10-25 08:56:47.002429+00 |
| updated_at | 2026-01-02 05:44:56.398879+00 |
| description | A lightweight, high-performance embedded database written in Rust with ACID guarantees |
| homepage | https://rustlite.dev |
| repository | https://github.com/VIRTUMEM-AI-LABS/rustlite |
| max_upload_size | |
| id | 1899991 |
| size | 198,155 |
RustLite is a lightweight, high-performance embedded database written entirely in Rust. Designed for applications that need a fast, reliable, and embeddable storage solution with ACID guarantees.
โ ๏ธ Important: RustLite is a key-value store with MVCC transactions, not a full relational database. It's similar to LevelDB or RocksDB (but with transactions), NOT SQLite or PostgreSQL. While it includes a basic SQL-like query engine for simple SELECT operations, it lacks schemas, CREATE TABLE, data types, functions, and constraints. For full SQL support, use rusqlite or SQLite directly.
RustLite aims to be the go-to embedded database for Rust applications, combining:
RustLite excels in scenarios where you need fast, transactional key-value storage:
Not Ideal For:
Add RustLite to your Cargo.toml:
[dependencies]
rustlite = "0.5"
use rustlite::{Database, IsolationLevel};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = Database::open("./my_database")?;
// Begin a transaction with snapshot isolation (default)
let mut txn = db.begin()?;
// All reads see a consistent snapshot
txn.put(b"account:alice".to_vec(), b"1000".to_vec())?;
txn.put(b"account:bob".to_vec(), b"500".to_vec())?;
// Transfer money atomically
let alice = txn.get(b"account:alice")?.unwrap();
let bob = txn.get(b"account:bob")?.unwrap();
let alice_bal: i32 = String::from_utf8_lossy(&alice).parse()?;
let bob_bal: i32 = String::from_utf8_lossy(&bob).parse()?;
txn.put(b"account:alice".to_vec(), (alice_bal - 200).to_string().into_bytes())?;
txn.put(b"account:bob".to_vec(), (bob_bal + 200).to_string().into_bytes())?;
// Commit (or rollback on error)
txn.commit()?;
Ok(())
}
Isolation Levels:
ReadUncommitted: Fastest, may see uncommitted changesReadCommitted: See only committed dataRepeatableRead: Snapshot isolation (default)Serializable: Strictest consistencySee examples/transaction_demo.rs for comprehensive examples.
use rustlite::Database;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open a persistent database (creates directory if needed)
let db = Database::open("./my_database")?;
// Insert data - automatically persisted to disk
db.put(b"user:1:name", b"Alice")?;
db.put(b"user:1:email", b"alice@example.com")?;
// Retrieve data
if let Some(name) = db.get(b"user:1:name")? {
println!("Name: {}", String::from_utf8_lossy(&name));
}
// Delete data
db.delete(b"user:1:email")?;
// Force sync to disk (optional - data is already durable via WAL)
db.sync()?;
Ok(())
}
use rustlite::Database;
// First run - write data
let db = Database::open("./my_database")?;
db.put(b"counter", b"42")?;
drop(db);
// Later - data is still there!
let db = Database::open("./my_database")?;
assert_eq!(db.get(b"counter")?, Some(b"42".to_vec()));
use rustlite::Database;
// Fast in-memory storage (data lost when program exits)
let db = Database::in_memory()?;
db.put(b"temp", b"data")?;
use rustlite::{Database, IndexType};
let db = Database::in_memory()?;
// Create indexes
db.create_index("users_by_email", IndexType::Hash)?; // O(1) lookups
db.create_index("users_by_name", IndexType::BTree)?; // Range queries
// Index your data
db.put(b"user:1", b"alice@example.com")?;
db.index_insert("users_by_email", b"alice@example.com", 1)?;
db.index_insert("users_by_name", b"Alice", 1)?;
// Fast lookups
let user_ids = db.index_find("users_by_email", b"alice@example.com")?;
println!("Found user: {}", user_ids[0]); // Output: 1
See examples/relational_demo.rs for a complete example showing:
cargo add rustlite
git clone https://github.com/VIRTUMEM-AI-LABS/rustlite.git
cd rustlite
cargo build --release
RustLite is built with a modular LSM-tree architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Database API โ
โ (rustlite crate) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Indexing โ โ Memtable โ โ WAL โ โ
โ โ B-Tree + โ โ (BTreeMap) โ โ (Write Log) โ โ
โ โ Hash โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ SSTable Storage + Compaction โ โ
โ โ (Sorted String Tables on Disk) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโ โ
โ โ Snapshot โ Point-in-time backups โ
โ โ Manager โ โ
โ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Components:
See docs/ARCHITECTURE.md for technical details and docs/README.md for the full documentation index.
RustLite includes production-grade structured logging:
use rustlite::logging::LogConfig;
use rustlite::Database;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize logging (info level to file with daily rotation)
let _guard = LogConfig::info()
.with_file("./logs/rustlite.log")
.init();
let db = Database::open("./data")?;
// All operations are now logged with structured context
db.put(b"key", b"value")?; // Logs: "Writing key-value pair" with sizes
Ok(())
}
See docs/LOGGING.md for comprehensive logging guide.
We welcome contributions! Please see our CONTRIBUTING.md for guidelines.
Key areas where we need help:
# Run all tests (48 tests: 39 lib + 9 aggregate)
cargo test --workspace
# Run with logging
RUST_LOG=debug cargo test
# Run examples
cargo run --example persistent_demo
cargo run --example relational_demo
cargo run --example aggregate_demo # NEW: GROUP BY and aggregates
# Run benchmarks
cargo bench
Performance benchmarks will be published as the project matures. Early benchmarks show:
RustLite takes security seriously. Please report any security vulnerabilities to security@rustlite.dev.
This project is licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in RustLite by you shall be under the terms and conditions of the Apache License, Version 2.0, without any additional terms or conditions.
RustLite is inspired by excellent databases like SQLite, LevelDB, and RocksDB.
Current Status: Active development (v0.3.0)
RustLite is in active development with persistent storage, WAL, and indexing capabilities. Not yet production-ready, but suitable for experimentation and development. Star the repo to follow our progress toward v1.0!
Made with โค๏ธ by the RustLite community