DatabaseManager

Struct DatabaseManager 

Source
pub struct DatabaseManager { /* private fields */ }
Expand description

DatabaseManager provides a centralized way to manage multiple models and their storage

Implementations§

Source§

impl DatabaseManager

Source

pub fn new() -> Self

Create a new DatabaseManager

Source

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 model
  • primary_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
Source

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

Source

pub fn get_simple_database<T>( &self, model_name: &str, ) -> Result<Database<T>, String>
where T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,

Create a database instance without secondary index

Source

pub fn insert<T>( &self, model_name: &str, key: &str, data: &T, ) -> Result<Document<T>, String>
where T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,

Insert data into a registered model’s database

Source

pub fn get<T>(&self, model_name: &str, key: &str) -> Result<T, String>
where T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,

Get data from a registered model’s database

Source

pub fn query<T>( &self, model_name: &str, page_size: usize, page_number: usize, ) -> Result<QueryResponse<T>, String>
where T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,

Query data from a registered model’s database

Source

pub fn list_models(&self) -> Vec<String>

List all registered models

Source

pub fn is_model_registered(&self, model_name: &str) -> bool

Check if a model is registered

Source

pub fn get_model_info( &self, model_name: &str, ) -> Option<(MemoryId, Option<MemoryId>)>

Get model information

Source

pub fn reserve_memory_range( &self, start: u8, end: u8, description: &str, ) -> Result<(), String>

Reserve memory IDs for a range (useful for ATP which uses 0-9)

Trait Implementations§

Source§

impl Default for DatabaseManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.