Skip to main content

CanisterSession

Struct CanisterSession 

Source
pub struct CanisterSession<C> { /* private fields */ }
Expand description

All store sessions for one declared canister. Clones share the same leases.

Implementations§

Source§

impl<C: CompiledCanister> CanisterSession<C>

Source

pub fn try_attach<F>( attach: impl FnMut(&CompiledStore) -> Result<DatabaseSession, F>, ) -> Result<Self, F>

Attach every store once, in compiled roster order. The host must acquire the lease named by each descriptor’s key and create or reopen it with that descriptor’s schema. A failed attachment drops collected handles. A host creating stores must trap its lifecycle message on failure to roll back any preceding creates.

§Errors

Returns the first host error without exposing a partially attached session.

Source

pub fn batch<S: MountedStore<Canister = C>>(&self) -> StoreBatch<'_, S>

Prepare dependent changes in one store, inferred from the entities added.

Source

pub fn query<'a, E: Entity<Store: MountedStore<Canister = C>>>( &self, ) -> Query<'a, E>

Build a live query in the entity’s declared store.

Source

pub fn get<E: Entity<Store: MountedStore<Canister = C>>>( &self, key: impl Into<Id<E>>, ) -> Result<Option<E>, Error>

Read an entity by its primary key.

§Errors

Propagates the owning store’s lookup errors.

Source

pub fn get_many<E: Entity<Store: MountedStore<Canister = C>>>( &self, keys: &[E::Key], ) -> Result<Vec<Option<E>>, Error>

Read up to 32 primary keys in input order, preserving duplicates and missing slots.

§Errors

Propagates the owning store session’s lookup and limit errors.

Source

pub fn get_unique<K: UniqueKey<Entity: Entity<Store: MountedStore<Canister = C>>>>( &self, key: &K, ) -> Result<Option<K::Entity>, Error>

Read an entity using its generated unique key.

§Errors

Propagates the owning store’s unique lookup errors.

Source

pub fn insert<E: Entity<Store: MountedStore<Canister = C>>>( &self, row: &E, ) -> Result<(), Error>

Insert one row in its declared store.

§Errors

Propagates batch preparation and commit errors.

Source

pub fn insert_input<I: InsertInput<Entity: Entity<Store: MountedStore<Canister = C>>>>( &self, input: I, ) -> Result<I::Entity, Error>

Insert one generated input in its declared store and return the committed row. Managed fields receive the current operation time.

§Errors

Propagates DatabaseSession::insert_input preparation and commit errors.

Source

pub fn replace<E: Entity<Store: MountedStore<Canister = C>>>( &self, row: &E, ) -> Result<E, Error>

Replace one row in its declared store and return the stored value.

§Errors

Propagates batch preparation and commit errors.

Source

pub fn delete<E: Entity<Store: MountedStore<Canister = C>>>( &self, key: impl Into<Id<E>>, ) -> Result<(), Error>

Delete one row from its declared store by primary key.

§Errors

Propagates batch preparation and commit errors.

Trait Implementations§

Source§

impl<C> Clone for CanisterSession<C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: CompiledCanister, E: Entity<Store: MountedStore<Canister = C>>> QuerySession<E> for CanisterSession<C>

Source§

fn entity_query<'a>(&self) -> Query<'a, E>

Build a live query. The builder owns the selected store handle.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for CanisterSession<C>

§

impl<C> !Send for CanisterSession<C>

§

impl<C> !Sync for CanisterSession<C>

§

impl<C> !UnwindSafe for CanisterSession<C>

§

impl<C> Forget for CanisterSession<C>

§

impl<C> Freeze for CanisterSession<C>
where PhantomData<fn() -> C>: Freeze,

§

impl<C> Move for CanisterSession<C>

§

impl<C> Unpin for CanisterSession<C>
where PhantomData<fn() -> C>: Unpin,

§

impl<C> UnsafeUnpin for CanisterSession<C>
where PhantomData<fn() -> C>: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.