pub struct Database<T, SecondaryKey = ()>where
T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,
SecondaryKey: Clone + Ord + Storable,{ /* private fields */ }
Expand description
Database implementation with support for primary and secondary indexes
Implementations§
Source§impl<T, SecondaryKey> Database<T, SecondaryKey>where
T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,
SecondaryKey: Storable + Ord + Clone,
impl<T, SecondaryKey> Database<T, SecondaryKey>where
T: CandidType + Serialize + for<'de> Deserialize<'de> + Clone,
SecondaryKey: Storable + Ord + Clone,
Sourcepub fn new(
map: RefCell<StableBTreeMap<CompositeKey, Document<T>, Memory>>,
secondary_index: Option<RefCell<StableBTreeMap<SecondaryKey, CompositeKeys, Memory>>>,
get_secondary_key: Option<Box<dyn Fn(&T) -> Option<SecondaryKey>>>,
) -> Self
pub fn new( map: RefCell<StableBTreeMap<CompositeKey, Document<T>, Memory>>, secondary_index: Option<RefCell<StableBTreeMap<SecondaryKey, CompositeKeys, Memory>>>, get_secondary_key: Option<Box<dyn Fn(&T) -> Option<SecondaryKey>>>, ) -> Self
Constructor to initialize the NoSQL database with an optional secondary index
Sourcepub fn insert(
&self,
partition_key: String,
sort_key: Option<String>,
data: T,
) -> Result<Document<T>, String>
pub fn insert( &self, partition_key: String, sort_key: Option<String>, data: T, ) -> Result<Document<T>, String>
Insert a document and update secondary index if applicable
Auto Trait Implementations§
impl<T, SecondaryKey = ()> !Freeze for Database<T, SecondaryKey>
impl<T, SecondaryKey = ()> !RefUnwindSafe for Database<T, SecondaryKey>
impl<T, SecondaryKey = ()> !Send for Database<T, SecondaryKey>
impl<T, SecondaryKey = ()> !Sync for Database<T, SecondaryKey>
impl<T, SecondaryKey> Unpin for Database<T, SecondaryKey>
impl<T, SecondaryKey = ()> !UnwindSafe for Database<T, SecondaryKey>
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