Expand description
obj — embedded document database (public crate).
This crate is the user-facing surface of the obj storage
engine. It wraps the obj-core building blocks (pager, WAL,
B+tree, codec, catalog, transaction layer) into the typed
Db / Collection<T> API described in design.md.
§Quick start
use obj::{Db, Document};
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
struct Order { customer_id: u64, total_cents: u64 }
impl Document for Order {
const COLLECTION: &'static str = "orders";
const VERSION: u32 = 1;
}
fn run() -> obj::Result<()> {
let db = Db::open("app.obj")?;
let id = db.insert(Order { customer_id: 1, total_cents: 100 })?;
let back: Option<Order> = db.get(id)?;
assert!(back.is_some());
Ok(())
}§unsafe policy
This crate is #![forbid(unsafe_code)]. All unsafe lives in
obj-core::platform.
Structs§
- Collection
- Typed handle to a collection.
- Collection
Stat - Per-collection summary inside
DbStat. - Config
Dbopen-time configuration. Construct viaConfig::defaultand modify with the builder methods.- Db
- The embedded document database.
- DbStat
- One-shot snapshot of a database’s header + catalog summary.
- Dump
Iter - Streaming iterator returned by
Db::dump_raw. - Dump
Record - One raw record yielded by
DumpIter. - Enum
Variant Schema - One variant of a
DynamicSchema::Enumdescription. - Id
- Per-collection document identifier.
- Index
Spec - A runtime index declaration.
- Integrity
Report - Structured result of an integrity check.
- IterAll
- Streaming iterator returned by
Db::iter_all. - Query
- The M8 query builder.
- ReadTxn
- Public read transaction. Acquired by
crate::Db::read_transaction. - Write
Txn - Public write transaction.
Enums§
- Dynamic
Schema - Describes the byte-stream shape of a postcard-encoded payload at one version. See module docs for the variant ↔ wire-format mapping.
- Error
- The pager-level error type.
- Index
Kind - What kind of secondary index a given
IndexSpecdeclares. - Integrity
Failure - Categorical reasons an integrity walk records a failure. Every variant carries the locus of the problem (page id, collection, index name, document id) so an operator can root-cause without re-running the check.
- Lock
Kind - Lock category for
Error::Busy. Three variants because the three categories of contention produce different operator guidance: a contended cross-processWRITER_LOCKmeans another process is writing; a contendedWriterInProcessmeans another thread of the same process is writing; a contended reader lock is unusual (31 slots, shared) and indicates either a saturated 31+-process workload or a stale lock left by a frozen process. - Sync
Mode - Durability mode for
FileHandle::sync_data.
Constants§
- MAX_
DISTINCT_ IDS - Per-call cap on the bounded
HashSet<Id>used byCollection::count_distinct_ids_in_rangeto count unique documentIds under anEachindex. Power-of-ten Rule 3: the distinct set is allocation-bounded; exceeding the cap surfacesobj_core::Error::DistinctCountExceededrather than chewing arbitrary memory. The user can narrow the range via.index_range(...)to fit inside the budget. - MAX_
SORT_ BUFFER - Default cap on the in-memory sort buffer. The query layer reads
at most this many surviving documents into RAM before sorting; a
scan that produces more candidates surfaces
Error::SortBufferExceeded. M8 #66.
Traits§
- Document
- The trait every user document type implements.
- Schema
- A type whose postcard wire shape is describable by a
DynamicSchema.
Type Aliases§
- Result
- Crate-local
Resultalias. Use this in new code unless an explicitstd::result::Resultis required for trait-impl reasons.
Derive Macros§
- Document
#[derive(obj::Document)]proc-macro re-export.