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 aDocId, 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-backedDb. Without it, the crate isno_stdand exposes only the in-memory document model (Value,Document).serde— derivesserde::Serialize/DeserializeforValueandDocument, 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§
- Db
std - An embedded document store backed by a single append-only file.
- DbOptions
std - Options for opening a
Db, built fluently and finished withopen. - DocId
std - A document’s primary key within a
Db. - Document
- An ordered collection of named fields — the record a store holds.
- Stats
std - A point-in-time summary of a store’s size and contents.
Enums§
- Error
- The set of failures a
bison-dboperation can produce. - Sync
Policy std - When a write is made durable on disk.
- Value
- A single field value inside a
Document.
Constants§
- MAX_
RECORD_ BYTES std - The largest record payload the store will write or accept while reading.