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
//! Type-safe wrapper around the [sled](https://docs.rs/sled) embedded database.
//!
//! This module provides a high-performance, type-safe interface to the underlying sled database,
//! using model discriminants as tree names and ensuring all operations are compile-time checked.
//!
//! # Module Organization
//!
//! The implementation is organized into submodules for better maintainability:
//!
//! ## Module Structure
//!
//! - `types.rs` - Shared types and enums (SecondaryKeyOp, etc.)
//! - `transaction.rs` - Transaction support (SledTransactionalTree)
//! - `tree.rs` - Tree implementation (SledStoreTree)
//! - `iterator.rs` - Iterator implementation (SledIter)
//! - `batch.rs` - Batch operations (SledBatchBuilder)
//! - `store.rs` - Main store implementation (SledStore)
//! - `trait_impls.rs` - Trait implementations (NetabaseTreeSync, StoreOps, etc.)
//!
//! # Examples
//!
//! ```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 your schema
//! #[netabase_definition_module(BlogDefinition, BlogKeys)]
//! mod blog {
//! use super::*;
//! use netabase_store::{netabase_definition_module, 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 name: String,
//! #[secondary_key]
//! pub email: String,
//! }
//! }
//!
//! use blog::*;
//!
//! // Create a temporary database for testing
//! let store = SledStore::<BlogDefinition>::temp().unwrap();
//!
//! // Open a type-safe tree for the User model
//! let user_tree = store.open_tree::<User>();
//!
//! // Insert a user
//! let alice = User {
//! id: 1,
//! name: "Alice".to_string(),
//! email: "alice@example.com".to_string(),
//! };
//! user_tree.put(alice.clone()).unwrap();
//!
//! // Retrieve by primary key
//! let retrieved = user_tree.get(alice.primary_key()).unwrap();
//! assert_eq!(retrieved, Some(alice));
//! ```
// Re-export the main types for external use
pub use SledBatchBuilder;
pub use SledIter;
pub use SledStore;
pub use SledTransactionalTree;
pub use SledStoreTree;
pub use SecondaryKeyOp;