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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//! # NGDB - High-Performance RocksDB Wrapper
//!
//! NGDB provides a clean, idiomatic Rust interface to RocksDB with zero async overhead
//! and built-in thread-safety.
//!
//! ## Features
//!
//! - **Synchronous API**: All operations are fast and synchronous - no async overhead
//! - **Type-safe**: Generic over key/value types with trait-based serialization
//! - **Zero RocksDB exposure**: Users never deal with RocksDB types directly
//! - **Thread-safe**: Built on `Arc` with multi-threaded column family support
//! - **Column Families**: Store multiple types in one database using collections
//! - **Efficient**: Multi-get operations, batching, transactions, and snapshots
//! - **Replication**: Built-in support for multi-node replication with conflict resolution
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use ngdb::{DatabaseConfig, Storable, ngdb};
//!
//! #[ngdb("users")]
//! struct User {
//! id: u64,
//! name: String,
//! email: String,
//! }
//!
//! impl Storable for User {
//! type Key = u64;
//! fn key(&self) -> Self::Key {
//! self.id
//! }
//! }
//!
//! fn main() -> Result<(), ngdb::Error> {
//! let db = DatabaseConfig::new("./data")
//! .create_if_missing(true)
//! .add_column_family("users")
//! .open()?;
//!
//! let user = User {
//! id: 1,
//! name: "Alice".to_string(),
//! email: "alice@example.com".to_string(),
//! };
//! user.save(&db)?;
//!
//! let users = User::collection(&db)?;
//! let retrieved: Option<User> = users.get(&1)?;
//! println!("Retrieved: {:?}", retrieved);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Batch Operations
//!
//! ```rust,no_run
//! # use ngdb::{Database, Storable};
//! # use borsh::{BorshSerialize, BorshDeserialize};
//! # #[derive(BorshSerialize, BorshDeserialize)]
//! # struct User { id: u64, name: String }
//! # impl Storable for User {
//! # type Key = u64;
//! # fn key(&self) -> u64 { self.id }
//! # }
//! # fn example(db: Database) -> Result<(), ngdb::Error> {
//! let users = db.collection::<User>("users")?;
//!
//! let mut batch = users.batch();
//! for i in 0..1000 {
//! batch.put(&User { id: i, name: format!("User {}", i) })?;
//! }
//! batch.commit()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Transactions
//!
//! ```rust,no_run
//! # use ngdb::{Database, Storable};
//! # use borsh::{BorshSerialize, BorshDeserialize};
//! # #[derive(BorshSerialize, BorshDeserialize)]
//! # struct Account { id: u64, balance: i64 }
//! # impl Storable for Account {
//! # type Key = u64;
//! # fn key(&self) -> u64 { self.id }
//! # }
//! # fn example(db: Database) -> Result<(), ngdb::Error> {
//! let txn = db.transaction()?;
//! let accounts = txn.collection::<Account>("accounts")?;
//!
//! accounts.put(&Account { id: 1, balance: 100 })?;
//! accounts.put(&Account { id: 2, balance: 200 })?;
//!
//! txn.commit()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Replication
//!
//! NGDB provides production-ready replication support for multi-node deployments:
//!
//! ```rust,no_run
//! # use ngdb::{DatabaseConfig, ReplicationConfig, ReplicationManager, ReplicationLog, ReplicationOperation};
//! # fn example() -> Result<(), ngdb::Error> {
//! // Setup replica node
//! let db = DatabaseConfig::new("./data/replica")
//! .create_if_missing(true)
//! .add_column_family("users")
//! .open()?;
//!
//! // Configure replication
//! let config = ReplicationConfig::new("replica-1")
//! .enable()
//! .with_peers(vec!["primary-1".to_string()]);
//!
//! let manager = ReplicationManager::new(db, config)?;
//!
//! // Apply replication logs from primary (received via network)
//! let log = ReplicationLog::new(
//! "primary-1".to_string(),
//! ReplicationOperation::Put {
//! collection: "users".to_string(),
//! key: vec![1, 2, 3],
//! value: vec![4, 5, 6],
//! },
//! ).with_checksum();
//!
//! manager.apply_replication(log)?;
//! # Ok(())
//! # }
//! ```
//!
//! Features:
//! - **Idempotent**: Safe to apply the same operation multiple times
//! - **Conflict Resolution**: LastWriteWins, FirstWriteWins, or Custom strategies
//! - **Checksums**: Optional data integrity verification
//! - **Hooks**: Extensible hook system for custom replication logic
//! - **Batching**: Efficient batch operation replication
//!
//! See the `replication` module and examples for more details.
// Public API exports
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export attribute macro
pub use ngdb;
/// Re-export commonly used types