obj-db 1.1.1

Embedded document database. Stable file format, full ACID, single-file portability.
Documentation

obj-db

The embedded document database for Rust. Dependable. Portable. Zero-infrastructure.

crates.io docs.rs

Part of obj — a self-contained, serverless, single-file document database with a stable file format and full ACID semantics. It is to document storage what SQLite is to relational storage.

Crate name obj-db; import as obj.

Stability. v1.0 froze the on-disk format (format_major = 1) and the public Rust API under strict SemVer. Backwards-incompatible changes require a 2.0 release with a migration tool; readers still open pre-1.0 (format_major = 0) files.


Quickstart

# Cargo.toml
[dependencies]
obj-db = "1.0"
serde = { version = "1", features = ["derive"] }
use obj::Db;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, obj::Document)]
struct Order {
    customer_id: u64,
    total_cents: u64,
}

fn main() -> obj::Result<()> {
    let dir = tempfile::tempdir()?;
    let db = Db::open(dir.path().join("app.obj"))?;
    let id = db.insert(Order { customer_id: 1, total_cents: 4_200 })?;
    let back: Order = db
        .get::<Order>(id)?
        .ok_or(obj::Error::InvalidArgument("just inserted"))?;
    assert_eq!(back.total_cents, 4_200);
    Ok(())
}

Collection name and schema version default to the type name and 1; override with #[obj(collection = "...", version = N)]. See the docs for queries, indexes, transactions, and migrations.


Features

All features are off by default — enable with cargo add obj-db --features <name>.

Feature What it does
serde Derive Serialize/Deserialize on public types; re-export both traits.
tracing Structured spans around open, transactions, queries, and checkpoints.
compression LZ4 per-page compression at the pager layer.
encryption ChaCha20-Poly1305 per-page at-rest encryption.
async Runtime-agnostic obj::asynchronous mirror of the blocking API.

See docs.rs/obj-db for per-feature details.


Documentation


License

Dual-licensed under MIT or Apache 2.0, at your option.