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>
impl<C: CompiledCanister> CanisterSession<C>
Sourcepub fn try_attach<F>(
attach: impl FnMut(&CompiledStore) -> Result<DatabaseSession, F>,
) -> Result<Self, F>
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.
Sourcepub fn batch<S: MountedStore<Canister = C>>(&self) -> StoreBatch<'_, S>
pub fn batch<S: MountedStore<Canister = C>>(&self) -> StoreBatch<'_, S>
Prepare dependent changes in one store, inferred from the entities added.
Sourcepub fn batch_at<S: MountedStore<Canister = C>>(
&self,
time: Timestamp,
) -> StoreBatch<'_, S>
pub fn batch_at<S: MountedStore<Canister = C>>( &self, time: Timestamp, ) -> StoreBatch<'_, S>
Prepare a batch with one host-captured timestamp for managed fields.
Sourcepub fn query<'a, E: Entity<Store: MountedStore<Canister = C>>>(
&self,
) -> Query<'a, E>
pub fn query<'a, E: Entity<Store: MountedStore<Canister = C>>>( &self, ) -> Query<'a, E>
Build a live query in the entity’s declared store.
Sourcepub fn get<E: Entity<Store: MountedStore<Canister = C>>>(
&self,
key: E::Key,
) -> Result<Option<E>, Error>
pub fn get<E: Entity<Store: MountedStore<Canister = C>>>( &self, key: E::Key, ) -> Result<Option<E>, Error>
Sourcepub fn get_many<E: Entity<Store: MountedStore<Canister = C>>>(
&self,
keys: &[E::Key],
) -> Result<Vec<Option<E>>, Error>
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.
Sourcepub fn get_unique<K: UniqueKey<Entity: Entity<Store: MountedStore<Canister = C>>>>(
&self,
key: &K,
) -> Result<Option<K::Entity>, Error>
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.
Sourcepub fn insert<E: Entity<Store: MountedStore<Canister = C>>>(
&self,
row: &E,
) -> Result<(), Error>
pub fn insert<E: Entity<Store: MountedStore<Canister = C>>>( &self, row: &E, ) -> Result<(), Error>
Sourcepub fn insert_input<I: InsertInput<Entity: Entity<Store: MountedStore<Canister = C>>>>(
&self,
input: I,
) -> Result<I::Entity, Error>
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.
For managed timestamps use Self::batch_at.
§Errors
Propagates DatabaseSession::insert_input preparation and commit errors.