pub struct DatabaseManager { /* private fields */ }
Expand description
DatabaseManager provides a centralized way to manage multiple models and their storage
Implementations§
Source§impl DatabaseManager
impl DatabaseManager
Sourcepub fn register_model(
&self,
model_name: &str,
primary_memory_id: Option<u8>,
secondary_memory_id: Option<u8>,
) -> Result<(), String>
pub fn register_model( &self, model_name: &str, primary_memory_id: Option<u8>, secondary_memory_id: Option<u8>, ) -> Result<(), String>
Register a model with the database manager
§Arguments
model_name
- Unique name for the modelprimary_memory_id
- Memory ID for primary storage (None for auto-allocation)secondary_memory_id
- Memory ID for secondary index (None for no secondary index)
§Returns
Result<(), String>
- Ok if registration successful, Err with message if failed
Sourcepub fn get_database<T, SecondaryKey>(
&self,
model_name: &str,
get_secondary_key: Option<Box<dyn Fn(&T) -> Option<SecondaryKey>>>,
) -> Result<Database<T, SecondaryKey>, String>where
T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,
SecondaryKey: Storable + Ord + Clone,
pub fn get_database<T, SecondaryKey>(
&self,
model_name: &str,
get_secondary_key: Option<Box<dyn Fn(&T) -> Option<SecondaryKey>>>,
) -> Result<Database<T, SecondaryKey>, String>where
T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,
SecondaryKey: Storable + Ord + Clone,
Create a database instance for a registered model
Sourcepub fn get_simple_database<T>(
&self,
model_name: &str,
) -> Result<Database<T>, String>
pub fn get_simple_database<T>( &self, model_name: &str, ) -> Result<Database<T>, String>
Create a database instance without secondary index
Sourcepub fn insert<T>(
&self,
model_name: &str,
key: &str,
data: &T,
) -> Result<Document<T>, String>
pub fn insert<T>( &self, model_name: &str, key: &str, data: &T, ) -> Result<Document<T>, String>
Insert data into a registered model’s database
Sourcepub fn get<T>(&self, model_name: &str, key: &str) -> Result<T, String>
pub fn get<T>(&self, model_name: &str, key: &str) -> Result<T, String>
Get data from a registered model’s database
Sourcepub fn query<T>(
&self,
model_name: &str,
page_size: usize,
page_number: usize,
) -> Result<QueryResponse<T>, String>
pub fn query<T>( &self, model_name: &str, page_size: usize, page_number: usize, ) -> Result<QueryResponse<T>, String>
Query data from a registered model’s database
Sourcepub fn list_models(&self) -> Vec<String>
pub fn list_models(&self) -> Vec<String>
List all registered models
Sourcepub fn is_model_registered(&self, model_name: &str) -> bool
pub fn is_model_registered(&self, model_name: &str) -> bool
Check if a model is registered
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DatabaseManager
impl !RefUnwindSafe for DatabaseManager
impl Send for DatabaseManager
impl !Sync for DatabaseManager
impl Unpin for DatabaseManager
impl UnwindSafe for DatabaseManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more