1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! # 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
//!
//! ```rust,ignore
//! use nitrite::nitrite_builder::NitriteBuilder;
//! use nitrite::collection::Document;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 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()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## 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
use crateSnowflakeIdGenerator;
use crate*;
use LazyLock;
use available_parallelism;
pub static FIELD_SEPARATOR: =
new;
pub static ID_GENERATOR: =
new;
pub static SCHEDULER: = new;
/// Returns the number of available CPU cores.
///
/// This function attempts to detect the number of available processors on the system.
/// If detection fails, it defaults to 1.
///
/// # Returns
///
/// A `usize` representing the number of available CPU cores.
///
/// # Examples
///
/// ```rust
/// use nitrite::get_cpu_count;
///
/// let cpu_count = get_cpu_count();
/// println!("Available CPUs: {}", cpu_count);
/// assert!(cpu_count > 0);
/// ```
// tests use assert!(true) as "reached without panic" markers