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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
//! # Netabase Store - Type-Safe Multi-Backend Key-Value Storage
//!
//! `netabase_store` is a type-safe, multi-backend key-value storage library that provides
//! a unified API across different database backends (Sled, Redb, IndexedDB). It uses procedural
//! macros to generate type-safe schemas and supports primary and secondary key indexing.
//!
//! ## Key Features
//!
//! - **Multi-Backend Support**: Choose between Sled (embedded DB), Redb (ACID compliant), or IndexedDB (browser)
//! - **Type-Safe Schema**: Derive macros generate compile-time checked schemas
//! - **Primary & Secondary Keys**: Efficient indexing with automatic secondary key management
//! - **Cross-Platform**: Supports both native and WASM targets
//! - **Zero-Copy Operations**: Efficient serialization with bincode
//! - **libp2p Integration**: Optional integration for distributed systems
//!
//! ## Quick Start
//!
//! ### Define Your Data Models
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel};
//!
//! // Define your schema with the definition module macro
//! #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! mod blog {
//! use super::*;
//! use netabase_store::{netabase, NetabaseModel};
//!
//! /// User model with primary and secondary keys
//! #[derive(
//! NetabaseModel,
//! Clone,
//! Debug,
//! PartialEq,
//! bincode::Encode,
//! bincode::Decode,
//! serde::Serialize,
//! serde::Deserialize,
//! )]
//! #[netabase(BlogDefinition)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub username: String,
//! #[secondary_key]
//! pub email: String,
//! pub age: u32,
//! }
//!
//! /// Post model associated with the same definition
//! #[derive(
//! NetabaseModel,
//! Clone,
//! Debug,
//! PartialEq,
//! bincode::Encode,
//! bincode::Decode,
//! serde::Serialize,
//! serde::Deserialize,
//! )]
//! #[netabase(BlogDefinition)]
//! pub struct Post {
//! #[primary_key]
//! pub id: String,
//! pub title: String,
//! pub author_id: u64,
//! #[secondary_key]
//! pub published: bool,
//! }
//! } // end mod blog
//!
//! use blog::*;
//! ```
//!
//! ### Using the Unified NetabaseStore (Recommended)
//!
//! ```rust
//! # use netabase_store::{NetabaseStore, netabase_definition_module, NetabaseModel, netabase};
//! # use netabase_store::traits::tree::NetabaseTreeSync;
//! # use netabase_store::traits::model::NetabaseModelTrait;
//!
//! # // Define your schema
//! # #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! # mod blog {
//! # use netabase_store::{NetabaseModel, netabase};
//!
//! # #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! # bincode::Encode, bincode::Decode,
//! # serde::Serialize, serde::Deserialize)]
//! # #[netabase(BlogDefinition)]
//! # pub struct User {
//! # #[primary_key]
//! # pub id: u64,
//! # pub username: String,
//! # #[secondary_key]
//! # pub email: String,
//! # pub age: u32,
//! # }
//! # }
//! # use blog::*;
//!
//! # fn main() -> Result<(), netabase_store::error::NetabaseError> {
//! // Create a store with any backend - Sled example (using temp for doctest)
//! let store = NetabaseStore::<BlogDefinition, _>::temp()?;
//!
//! // Or use Redb (in production):
//! // let store = NetabaseStore::<BlogDefinition, _>::redb("./my_db.redb")?;
//!
//! // Open a tree for the User model - works with any backend!
//! let user_tree = store.open_tree::<User>();
//!
//! // Standard operations work the same across all backends
//! let alice = User {
//! id: 1,
//! username: "alice".to_string(),
//! email: "alice@example.com".to_string(),
//! age: 30,
//! };
//!
//! user_tree.put(alice.clone())?;
//! let retrieved = user_tree.get(alice.primary_key())?.unwrap();
//! assert_eq!(retrieved, alice);
//!
//! // Backend-specific features still available
//! store.flush()?; // Sled-specific
//! # Ok(())
//! # }
//! ```
//!
//! ### Using Sled Backend (Direct)
//!
//! ```rust
//! # use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! # use netabase_store::databases::sled_store::SledStore;
//! # use netabase_store::traits::tree::NetabaseTreeSync;
//! # use netabase_store::traits::model::NetabaseModelTrait;
//! #
//! # // Define schema for this example
//! # #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! # mod blog {
//! # use super::*;
//! # use netabase_store::{NetabaseModel, netabase};
//! #
//! # #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! # bincode::Encode, bincode::Decode,
//! # serde::Serialize, serde::Deserialize)]
//! # #[netabase(BlogDefinition)]
//! # pub struct User {
//! # #[primary_key]
//! # pub id: u64,
//! # pub username: String,
//! # #[secondary_key]
//! # pub email: String,
//! # pub age: u32,
//! # }
//! # }
//! use blog::*;
//!
//! // Open a database
//! let store = SledStore::<BlogDefinition>::temp().unwrap();
//!
//! // Get a type-safe tree for the User model
//! let user_tree = store.open_tree::<User>();
//!
//! // Create a user
//! let alice = User {
//! id: 1,
//! username: "alice".to_string(),
//! email: "alice@example.com".to_string(),
//! age: 30,
//! };
//!
//! // Insert the user
//! user_tree.put(alice.clone()).unwrap();
//!
//! // Retrieve by primary key
//! let retrieved = user_tree.get(alice.primary_key()).unwrap().unwrap();
//! assert_eq!(retrieved, alice);
//!
//! // Query by secondary key (email) using convenience function
//! use blog::AsUserEmail;
//! let users_by_email = user_tree
//! .get_by_secondary_key("alice@example.com".as_user_email_key())
//! .unwrap();
//! assert_eq!(users_by_email.len(), 1);
//!
//! // Update the user
//! let mut alice_updated = alice.clone();
//! alice_updated.age = 31;
//! user_tree.put(alice_updated).unwrap();
//!
//! // Remove the user
//! user_tree.remove(alice.primary_key()).unwrap();
//! ```
//!
//! ### Using Redb Backend (Native)
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//!
//! # // Define your schema with the definition module macro
//! # #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! # mod blog {
//! # use super::*;
//! # use netabase_store::{netabase, NetabaseModel};
//! #
//! # /// User model with primary and secondary keys
//! # #[derive(
//! # NetabaseModel,
//! # Clone,
//! # Debug,
//! # PartialEq,
//! # bincode::Encode,
//! # bincode::Decode,
//! # serde::Serialize,
//! # serde::Deserialize,
//! # )]
//! # #[netabase(BlogDefinition)]
//! # pub struct User {
//! # #[primary_key]
//! # pub id: u64,
//! # pub username: String,
//! # #[secondary_key]
//! # pub email: String,
//! # pub age: u32,
//! # }
//! #
//! # /// Post model associated with the same definition
//! # #[derive(
//! # NetabaseModel,
//! # Clone,
//! # Debug,
//! # PartialEq,
//! # bincode::Encode,
//! # bincode::Decode,
//! # serde::Serialize,
//! # serde::Deserialize,
//! # )]
//! # #[netabase(BlogDefinition)]
//! # pub struct Post {
//! # #[primary_key]
//! # pub id: String,
//! # pub title: String,
//! # pub author_id: u64,
//! # #[secondary_key]
//! # pub published: bool,
//! # }
//! # } // end mod blog
//! #
//! # use blog::*;
//! # use netabase_store::databases::redb_store::RedbStore;
//! # use netabase_store::traits::tree::NetabaseTreeSync;
//! # use netabase_store::traits::model::NetabaseModelTrait;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open a database with Redb backend (using temp file for doctest)
//! let temp_dir = tempfile::tempdir()?;
//! let db_path = temp_dir.path().join("test.redb");
//! let store = RedbStore::<BlogDefinition>::new(db_path)?;
//!
//! // API is identical to SledStore
//! let user_tree = store.open_tree::<User>();
//!
//! let user = User {
//! id: 1,
//! username: "bob".to_string(),
//! email: "bob@example.com".to_string(),
//! age: 25,
//! };
//! user_tree.put(user)?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Using IndexedDB Backend (WASM)
//!
//! IndexedDB backend provides persistent storage in web browsers.
//! This example requires the `wasm` feature and wasm32 target:
//!
//! ```
//! # # #[cfg(all(target_arch = "wasm32", feature = "wasm"))]
//! # # {
//! # use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! # use netabase_store::databases::indexeddb_store::IndexedDBStore;
//! # use netabase_store::traits::tree::NetabaseTreeAsync;
//! # use netabase_store::traits::model::NetabaseModelTrait;
//! #
//! # #[netabase_definition_module(AppDefinition, AppKeys)]
//! # mod app {
//! # use super::*;
//! # use netabase_store::{NetabaseModel, netabase};
//! #
//! # #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! # bincode::Encode, bincode::Decode,
//! # serde::Serialize, serde::Deserialize)]
//! # #[netabase(AppDefinition)]
//! # pub struct User {
//! # #[primary_key]
//! # pub id: u64,
//! # pub username: String,
//! # #[secondary_key]
//! # pub email: String,
//! # }
//! # }
//! # use app::*;
//!
//! async fn wasm_example() -> Result<(), Box<dyn std::error::Error>> {
//! // Open a database in the browser (persists across page reloads)
//! let store = IndexedDBStore::<AppDefinition>::new("my_app_db").await?;
//!
//! // Get an async tree - note WASM uses async API
//! let user_tree = store.open_tree::<User>();
//!
//! // Create a user
//! let alice = User {
//! id: 1,
//! username: "alice".into(),
//! email: "alice@example.com".into()
//! };
//!
//! // All operations are async in WASM
//! user_tree.put(alice.clone()).await?;
//! let retrieved = user_tree.get(alice.primary_key()).await?;
//!
//! // Query by secondary key using convenience function
//! use app::AsUserEmail;
//! let users_by_email = user_tree
//! .get_by_secondary_key("alice@example.com".as_user_email_key())
//! .await?;
//!
//! Ok(())
//! }
//! # }
//! ```
//!
//! ## Using the Configuration
//!
//! ```no_run
//! # use netabase_store::traits::backend_store::BackendStore;
//! # use netabase_store::config::FileConfig;
//! # use netabase_store::databases::sled_store::SledStore;
//! # use netabase_store::netabase_definition_module;
//! # #[netabase_definition_module(MyDef, MyKeys)]
//! # mod models {
//! # use netabase_store::{NetabaseModel, netabase};
//! # #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! # bincode::Encode, bincode::Decode,
//! # serde::Serialize, serde::Deserialize)]
//! # #[netabase(MyDef)]
//! # pub struct User {
//! # #[primary_key]
//! # pub id: u64,
//! # pub name: String,
//! # }
//! # }
//! # use models::*;
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use netabase_store::traits::backend_store::BackendStore;
//! // Unified API across all backends via BackendStore trait
//! let temp_dir = tempfile::tempdir()?;
//! let config = FileConfig::new(temp_dir.path().join("my_store.db"));
//! let store = <SledStore<MyDef> as BackendStore<MyDef>>::new(config.clone())?;
//!
//! // Or open existing
//! let store = <SledStore<MyDef> as BackendStore<MyDef>>::open(config)?;
//!
//! // Temporary store
//! let temp_store = <SledStore<MyDef> as BackendStore<MyDef>>::temp()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Batch Operations
//!
//! For high-performance bulk operations, use batch processing to reduce overhead.
//! This example requires the `native` feature:
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! use netabase_store::databases::sled_store::SledStore;
//! use netabase_store::traits::batch::{Batchable, BatchOperations};
//! use netabase_store::traits::model::NetabaseModelTrait;
//!
//! #[netabase_definition_module(AppDefinition, AppKeys)]
//! mod app {
//! use super::*;
//! use netabase_store::{NetabaseModel, netabase};
//!
//! #[derive(NetabaseModel, Clone, Debug,
//! bincode::Encode, bincode::Decode,
//! serde::Serialize, serde::Deserialize)]
//! #[netabase(AppDefinition)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub name: String,
//! }
//! }
//! use app::*;
//!
//! # fn main() -> Result<(), netabase_store::error::NetabaseError> {
//! let store = SledStore::<AppDefinition>::temp()?;
//! let user_tree = store.open_tree::<User>();
//!
//! // Prepare batch of users
//! let users: Vec<User> = (0..1000)
//! .map(|i| User { id: i, name: format!("User {}", i) })
//! .collect();
//!
//! // Bulk insert - much faster than individual puts
//! user_tree.put_batch(users)?;
//! # Ok(())
//! # }
//! ```
//!
//! Batch operations are atomic and significantly faster than individual operations
//! when working with many records.
//!
//! ## Zero-Copy Redb Backend (High Performance)
//!
//! For maximum performance with the Redb backend, use the zero-copy API that provides
//! explicit transaction control and zero-copy reads.
//!
//! ### Enabling Zero-Copy
//!
//! Add both `redb` and `redb-zerocopy` features:
//!
//! ```toml
//! [dependencies]
//! netabase_store = { version = "*", features = ["redb", "redb-zerocopy"] }
//! ```
//!
//! ### Performance Characteristics
//!
//! | Operation | Regular API | Zero-Copy API | Speedup |
//! |-----------|------------|---------------|---------|
//! | Bulk insert (1000 items) | ~50ms | ~5ms | **10x faster** |
//! | Secondary key query | ~5.4ms | ~100μs | **54x faster** |
//! | Single read | ~100ns | ~100ns | Similar |
//!
//! ### Usage Example
//!
//! ```no_run
//! // This example requires the `redb-zerocopy` feature
//! use netabase_store::{netabase_definition_module, NetabaseModel};
//! use netabase_store::databases::redb_zerocopy::RedbStoreZeroCopy;
//! use netabase_store::traits::model::NetabaseModelTrait;
//!
//! #[netabase_definition_module(AppDef, AppKeys)]
//! mod app {
//! use netabase_store::{NetabaseModel, netabase};
//! #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! bincode::Encode, bincode::Decode,
//! serde::Serialize, serde::Deserialize)]
//! #[netabase(AppDef)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub name: String,
//! #[secondary_key]
//! pub email: String,
//! }
//! }
//! use app::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # let temp_dir = tempfile::tempdir()?;
//! // Create a zero-copy store
//! let store = RedbStoreZeroCopy::<AppDef>::new(temp_dir.path().join("app.redb"))?;
//!
//! // Write transaction - batch multiple operations
//! let mut write_txn = store.begin_write()?;
//! let mut tree = write_txn.open_tree::<User>()?;
//!
//! // Batch insert 1000 users in one transaction
//! for i in 0..1000 {
//! tree.put(User {
//! id: i,
//! name: format!("User {}", i),
//! email: format!("user{}@example.com", i),
//! })?;
//! }
//! drop(tree);
//! write_txn.commit()?; // All 1000 inserts committed atomically
//!
//! // Read transaction - efficient queries
//! let read_txn = store.begin_read()?;
//! let tree = read_txn.open_tree::<User>()?;
//! let user = tree.get(&UserPrimaryKey(42))?.unwrap();
//! assert_eq!(user.name, "User 42");
//! # Ok(())
//! # }
//! ```
//!
//! ### When to Use Zero-Copy API
//!
//! **Use zero-copy when:**
//! - You need to batch multiple operations (bulk inserts/updates)
//! - Performance is critical
//! - You want explicit transaction control
//! - You're doing many secondary key queries
//!
//! **Use regular API when:**
//! - Simplicity is more important than performance
//! - Single-operation transactions are fine
//! - You want the simplest possible code
//!
//! ### Available Types
//!
//! When `redb-zerocopy` feature is enabled, these types are re-exported at the crate root:
//! - `RedbStoreZeroCopy` - The zero-copy store
//! - `RedbWriteTransactionZC` - Write transaction handle
//! - `RedbReadTransactionZC` - Read transaction handle
//! - `RedbTreeMut` - Mutable tree for write transactions
//! - `RedbTree` - Immutable tree for read transactions
//! - `BorrowedGuard` - Guard for zero-copy borrowed data
//! - `BorrowedIter` - Iterator for zero-copy iteration
//!
//! ## Custom Backend Implementations
//!
//! Netabase Store provides a unified API through traits, making it easy to implement
//! custom storage backends:
//!
//! - **`NetabaseTreeSync`**: For synchronous backends (native)
//! - **`NetabaseTreeAsync`**: For asynchronous backends (WASM, remote databases)
//! - **`OpenTree`**: For creating tree instances from stores
//! - **`Batchable`**: For batch operation support
//!
//! Implement these traits to add support for new databases while maintaining
//! compatibility with all existing code using netabase_store.
//!
//! ## Architecture
//!
//! ### Core Components
//!
//! 1. **Definition Module**: Groups related models into a schema
//! - Created with `#[netabase_definition_module]` macro
//! - Generates an enum containing all models
//! - Generates a keys enum for type-safe queries
//!
//! 2. **Models**: Individual data structures
//! - Derived with `#[derive(NetabaseModel)]`
//! - Must have one `#[primary_key]`
//! - Can have multiple `#[secondary_key]` fields
//!
//! 3. **Storage Backends**:
//! - **SledStore**: Fast embedded database, native only
//! - **RedbStore**: ACID-compliant embedded DB, native only
//! - **IndexedDBStore**: Browser storage, WASM only
//!
//! 4. **Traits**:
//! - `NetabaseTreeSync`: Synchronous CRUD operations (native)
//! - `NetabaseTreeAsync`: Asynchronous CRUD operations (WASM)
//! - `NetabaseModelTrait`: Core model trait
//! - `NetabaseDefinitionTrait`: Schema trait
//!
//! ## Secondary Key Queries
//!
//! Secondary keys enable efficient querying by non-primary fields:
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! use netabase_store::databases::sled_store::SledStore;
//! use netabase_store::traits::tree::NetabaseTreeSync;
//! use netabase_store::traits::model::NetabaseModelTrait;
//!
//! #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! mod blog {
//! use super::*;
//! use netabase_store::{NetabaseModel, netabase};
//! #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! bincode::Encode, bincode::Decode,
//! serde::Serialize, serde::Deserialize)]
//! #[netabase(BlogDefinition)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub username: String,
//! #[secondary_key]
//! pub email: String,
//! }
//! }
//! use blog::*;
//!
//! let store = SledStore::<BlogDefinition>::temp().unwrap();
//! let user_tree = store.open_tree::<User>();
//!
//! let user = User { id: 1, username: "alice".into(), email: "alice@example.com".into() };
//! user_tree.put(user.clone()).unwrap();
//!
//! // Query by email (secondary key) using convenience function
//! use blog::AsUserEmail;
//! let users = user_tree
//! .get_by_secondary_key("alice@example.com".as_user_email_key())
//! .unwrap();
//!
//! // Multiple users can have the same secondary key value
//! for user in users {
//! println!("Found user: {}", user.username);
//! }
//! ```
//!
//! ## Iteration
//!
//! Iterate over all records in a tree:
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! use netabase_store::databases::sled_store::SledStore;
//!
//! #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! mod blog {
//! use super::*;
//! use netabase_store::{NetabaseModel, netabase};
//! #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! bincode::Encode, bincode::Decode,
//! serde::Serialize, serde::Deserialize)]
//! #[netabase(BlogDefinition)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub username: String,
//! #[secondary_key]
//! pub email: String,
//! }
//! }
//! use blog::*;
//!
//! let store = SledStore::<BlogDefinition>::temp().unwrap();
//! let user_tree = store.open_tree::<User>();
//!
//! // Iterate over all users
//! for result in user_tree.iter() {
//! let (_key, user) = result.unwrap();
//! println!("User: {} ({})", user.username, user.email);
//! }
//! ```
//!
//! ## Testing
//!
//! Use temporary databases for testing:
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! use netabase_store::databases::sled_store::SledStore;
//! use netabase_store::traits::tree::NetabaseTreeSync;
//!
//! #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! mod blog {
//! use super::*;
//! use netabase_store::{NetabaseModel, netabase};
//! #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! bincode::Encode, bincode::Decode,
//! serde::Serialize, serde::Deserialize)]
//! #[netabase(BlogDefinition)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub username: String,
//! }
//! }
//! use blog::*;
//!
//! // Create an database in tmp database for testing
//! let store = SledStore::<BlogDefinition>::temp().unwrap();
//! let user_tree = store.open_tree::<User>();
//!
//! // Perform test operations
//! let test_user = User { id: 1, username: "test".into() };
//! user_tree.put(test_user).unwrap();
//! // ... assertions
//! ```
//!
//! ## libp2p Integration
//!
//! When using the `libp2p` feature, stores can be used as record stores for Kademlia DHT. This was designed to to be implementned with the
//! [netabase](https://github.com/newsnet-africa/netabase.git) crate, which (eventually) should be a dht networking layer abstraction.
//! The stores in the [databases module](crate::databases) implement [RecordStore](https://docs.rs/libp2p/latest/libp2p/kad/store/trait.RecordStore.html), which allow for the [libp2p's kademlia implementation](https://docs.rs/libp2p/latest/libp2p/kad/index.html).
//!
//!
//! ## Feature Flags
//!
//! - `sled` - Enable Sled backend (default, native only)
//! - `redb` - Enable Redb backend (native only)
//! - `wasm` - Enable IndexedDB backend (WASM only)
//! - `libp2p` - Enable libp2p RecordStore integration
//!
//! ## Error Handling
//!
//! All operations return `Result<T, NetabaseError>`:
//!
//! ```rust
//! use netabase_store::{netabase_definition_module, NetabaseModel, netabase};
//! use netabase_store::databases::sled_store::SledStore;
//! use netabase_store::traits::tree::NetabaseTreeSync;
//! use netabase_store::traits::model::NetabaseModelTrait;
//!
//! #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! mod blog {
//! use super::*;
//! use netabase_store::{NetabaseModel, netabase};
//! #[derive(NetabaseModel, Clone, Debug, PartialEq,
//! bincode::Encode, bincode::Decode,
//! serde::Serialize, serde::Deserialize)]
//! #[netabase(BlogDefinition)]
//! pub struct User {
//! #[primary_key]
//! pub id: u64,
//! pub username: String,
//! }
//! }
//! use blog::*;
//!
//! let store = SledStore::<BlogDefinition>::temp().unwrap();
//! let user_tree = store.open_tree::<User>();
//!
//! let user = User { id: 1, username: "alice".into() };
//! match user_tree.get(user.primary_key()) {
//! Ok(Some(user)) => println!("Found: {}", user.username),
//! Ok(None) => println!("User not found"),
//! Err(e) => eprintln!("Database error: {}", e),
//! }
//! ```
// NOTE: Phase 4 - guards module re-enabled with proper architecture
// Guard-based API now works with proper lifetime management
// Re-export netabase_deps for users of the macros
pub use netabase_deps;
pub use *;
// Re-export macros for convenience
pub use *;
pub use NetabaseStore;
pub use DefaultSubscriptionManager;
pub use ModelHash;
pub use *;
pub use ;
pub use ;
// Re-export zero-copy redb types for convenience
pub use ;
pub use ;
// Conditional Send + Sync bounds for WASM compatibility
// Helper trait to bundle all discriminant requirements
// Blanket implementation