Database

Struct Database 

Source
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,

Source

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

Source

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

Source

pub fn get( &self, partition_key: &str, sort_key: Option<String>, ) -> Result<Document<T>, String>

Get a single document by partition key and optional sort key

Source

pub fn query( &self, partition_key: Option<&str>, secondary_key: Option<SecondaryKey>, page_size: usize, page_number: usize, ) -> Result<QueryResponse<T>, String>

Query by either partition key or secondary index with pagination

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>
where T: Unpin, SecondaryKey: Unpin,

§

impl<T, SecondaryKey = ()> !UnwindSafe for Database<T, SecondaryKey>

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.