Expand description
§Nitrite - Embedded NoSQL Database
Nitrite is a lightweight, feature-rich, embedded NoSQL database written in Rust. It provides document and object storage with rich querying capabilities, indexing, and transaction support.
§Key Features
- Embedded: No separate server process required
- NoSQL: Document-based and object-oriented storage
- Rich Querying: Powerful filter API with support for complex queries
- Indexing: Support for unique, non-unique, and full-text indexes
- Spatial: Geographic and spatial data support through the
nitrite-spatialcrate - Transactions: ACID transaction support
- Migration: Schema migration management
- Events: Event listeners for database, collection, and store events
- Multiple Storage Backends: In-memory storage and pluggable store providers
- Clean API: PIMPL pattern provides stable, encapsulated interface
§Quick Start
ⓘ
use nitrite::nitrite_builder::NitriteBuilder;
use nitrite::collection::Document;
// Create or open a database
let db = Nitrite::builder()
.open_or_create(None, None)?;
// Get or create a collection
let mut collection = db.collection("users")?;
// Create a document
let mut doc = Document::new();
doc.put("name", "John Doe")?;
doc.put("age", 30i64)?;
// Insert the document
collection.insert(doc)?;
// Find documents using filters
let filter = nitrite::filter::all();
let results = collection.find(filter)?;
// Close the database
db.close()?;§Design Pattern
Nitrite uses the PIMPL (Pointer To IMPLementation) design pattern to provide:
- Encapsulation: Implementation details are completely hidden
- API Stability: Public interface is stable and can evolve independently
- Implementation Flexibility: Internal structure can be refactored without affecting users
- Thread Safety: All clones share the same underlying state through
Arc<NitriteInner>
This design ensures that the Nitrite database provides a clean, stable API while keeping implementation complexity hidden.
§Module Organization
collection- Document collections, repositories, and document operationscommon- Common types, traits, and utilitieserrors- Error types and result definitionsfilter- Query filters and filter providersindex- Indexing support (unique, non-unique, full-text)metadata- Database metadata managementmigration- Schema migration supportnitrite- Core database interfacenitrite_builder- Database builder for initializationnitrite_config- Database configurationrepository- Type-safe object repositoriesstore- Storage backend abstractionstransaction- Transaction support
Modules§
- collection
- Collections and documents for schemaless data storage.
- common
- errors
- filter
- Query filters for selecting documents from collections.
- index
- Indexing support for optimized querying.
- metadata
- migration
- Schema migration support for database evolution.
- nitrite
- nitrite_
builder - nitrite_
config - Configuration management for Nitrite database.
- repository
- Object repositories for type-safe data persistence.
- store
- Storage backends and abstractions.
- transaction
- Transaction module for Nitrite
Macros§
- doc
- Creates a Nitrite Document with JSON-like syntax.
- doc_
value - Helper macro to convert values for the doc! macro. Handles nested documents, arrays, and expressions.
- key
- val
- A macro to create a
Valuefrom a given expression.
Functions§
- get_
cpu_ count - Returns the number of available CPU cores.