Skip to main content

Crate nitrite

Crate nitrite 

Source
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-spatial crate
  • 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 operations
  • common - Common types, traits, and utilities
  • errors - Error types and result definitions
  • filter - Query filters and filter providers
  • index - Indexing support (unique, non-unique, full-text)
  • metadata - Database metadata management
  • migration - Schema migration support
  • nitrite - Core database interface
  • nitrite_builder - Database builder for initialization
  • nitrite_config - Database configuration
  • repository - Type-safe object repositories
  • store - Storage backend abstractions
  • transaction - 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 Value from a given expression.

Functions§

get_cpu_count
Returns the number of available CPU cores.