Skip to main content

Crate bison_db

Crate bison_db 

Source
Expand description

§bison-db

An embedded, document-oriented database for Rust: store, index, and query schemaless documents entirely in-process, with no server, no network, and no external services. The whole database is one file — trivial to ship, copy, and back up — and every write is appended to a checksummed log, so a crash never leaves a half-written record behind.

bison-db is the first member of the Bison family of embedded databases.

§The shape of the API

Three types carry the everyday workflow:

  • Document — an ordered set of named fields, the record you store.
  • Value — the content of a field: null, bool, integer, float, string, bytes, array, or a nested document.
  • Db — the single-file store. Insert a document to get a DocId, then read, overwrite, or delete it by that id.

§Quick start

use bison_db::{Db, Document};

// Open (or create) a store backed by a single file.
let mut db = Db::open(&path)?;

// Build a schemaless document and insert it.
let mut song = Document::new();
song.set("title", "Take Five").set("year", 1959_i64).set("live", false);
let id = db.insert(song)?;

// Read it back by id.
let stored = db.get(id)?.expect("just inserted");
assert_eq!(stored.get("title").and_then(|v| v.as_str()), Some("Take Five"));

// Overwrite, delete, and make it durable.
db.update(id, { let mut d = Document::new(); d.set("title", "So What"); d })?;
assert!(db.delete(id)?);
db.flush()?;

§Feature flags

  • std (default) — enables the file-backed Db. Without it, the crate is no_std and exposes only the in-memory document model (Value, Document).
  • serde — derives serde::Serialize/Deserialize for Value and Document, so documents move in and out of any serde data format.

§Durability and recovery

Writes are visible to later reads immediately and become durable against power loss after Db::flush. On open, the log is replayed and verified; a record torn by a crash is detected by its length and CRC-32C checksum and truncated, never silently misread. See Db::open for the full contract.

Structs§

Dbstd
An embedded document store backed by a single append-only file.
DbOptionsstd
Options for opening a Db, built fluently and finished with open.
DocIdstd
A document’s primary key within a Db.
Document
An ordered collection of named fields — the record a store holds.
Statsstd
A point-in-time summary of a store’s size and contents.

Enums§

Error
The set of failures a bison-db operation can produce.
SyncPolicystd
When a write is made durable on disk.
Value
A single field value inside a Document.

Constants§

MAX_RECORD_BYTESstd
The largest record payload the store will write or accept while reading.

Type Aliases§

Result
A specialised Result for bison-db operations.