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
//! Unified backend store trait for consistent database initialization.
//!
//! This trait provides a standard interface for creating and opening databases
//! across all backends, replacing the previous `BackendConstructor` pattern.
use crateNetabaseError;
use crateNetabaseDefinitionTrait;
use Path;
/// Unified interface for database backend initialization.
///
/// All database backends should implement this trait to provide consistent
/// constructor APIs: `new()`, `open()`, and `temp()`.
///
/// # Type Parameters
///
/// * `D` - The definition type (generated by `#[netabase_definition_module]`)
/// * `Config` - Backend-specific configuration type
///
/// # Examples
///
/// ```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(())
/// # }
/// ```
/// Helper trait for backends that support path-based configuration.
///
/// This provides convenient shortcuts for the most common case.