pub struct DbSession<C: CanisterKind> { /* private fields */ }Expand description
DbSession Database handle plus a debug flag that controls executor verbosity.
Implementations§
Source§impl<C: CanisterKind> DbSession<C>
impl<C: CanisterKind> DbSession<C>
Sourcepub const fn metrics_sink(self, sink: &'static dyn MetricsSink) -> Self
pub const fn metrics_sink(self, sink: &'static dyn MetricsSink) -> Self
Override the metrics sink for operations executed through this session.
Sourcepub const fn load<E>(&self) -> LoadExecutor<E>where
E: EntityKind<Canister = C>,
pub const fn load<E>(&self) -> LoadExecutor<E>where
E: EntityKind<Canister = C>,
Get a LoadExecutor for building and executing queries that read entities.
Note: executor methods do not apply the session metrics override.
Sourcepub const fn save<E>(&self) -> SaveExecutor<E>where
E: EntityKind<Canister = C>,
pub const fn save<E>(&self) -> SaveExecutor<E>where
E: EntityKind<Canister = C>,
Get a SaveExecutor for inserting or updating entities.
Normally you will use the higher-level create/replace/update shortcuts instead.
Note: executor methods do not apply the session metrics override.
Sourcepub const fn upsert<E>(&self) -> UpsertExecutor<E>
pub const fn upsert<E>(&self) -> UpsertExecutor<E>
Get an UpsertExecutor for inserting or updating by a unique index.
Note: executor methods do not apply the session metrics override.
Sourcepub const fn delete<E>(&self) -> DeleteExecutor<E>where
E: EntityKind<Canister = C>,
pub const fn delete<E>(&self) -> DeleteExecutor<E>where
E: EntityKind<Canister = C>,
Get a DeleteExecutor for deleting entities by key or query.
Note: executor methods do not apply the session metrics override.
Sourcepub fn insert<E>(&self, entity: E) -> Result<E, InternalError>where
E: EntityKind<Canister = C>,
pub fn insert<E>(&self, entity: E) -> Result<E, InternalError>where
E: EntityKind<Canister = C>,
Insert a new entity, returning the stored value.
Sourcepub fn insert_many<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<Vec<E>, InternalError>where
E: EntityKind<Canister = C>,
pub fn insert_many<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<Vec<E>, InternalError>where
E: EntityKind<Canister = C>,
Insert multiple entities, returning stored values.
Sourcepub fn replace<E>(&self, entity: E) -> Result<E, InternalError>where
E: EntityKind<Canister = C>,
pub fn replace<E>(&self, entity: E) -> Result<E, InternalError>where
E: EntityKind<Canister = C>,
Replace an existing entity or insert it if it does not yet exist.
Sourcepub fn replace_many<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<Vec<E>, InternalError>where
E: EntityKind<Canister = C>,
pub fn replace_many<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<Vec<E>, InternalError>where
E: EntityKind<Canister = C>,
Replace multiple entities, inserting if missing.
Sourcepub fn update<E>(&self, entity: E) -> Result<E, InternalError>where
E: EntityKind<Canister = C>,
pub fn update<E>(&self, entity: E) -> Result<E, InternalError>where
E: EntityKind<Canister = C>,
Partially update an existing entity.
Sourcepub fn update_many<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<Vec<E>, InternalError>where
E: EntityKind<Canister = C>,
pub fn update_many<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<Vec<E>, InternalError>where
E: EntityKind<Canister = C>,
Partially update multiple existing entities.
Sourcepub fn insert_view<E>(
&self,
view: E::ViewType,
) -> Result<E::ViewType, InternalError>where
E: EntityKind<Canister = C>,
pub fn insert_view<E>(
&self,
view: E::ViewType,
) -> Result<E::ViewType, InternalError>where
E: EntityKind<Canister = C>,
Insert a new view value for an entity.
Sourcepub fn replace_view<E>(
&self,
view: E::ViewType,
) -> Result<E::ViewType, InternalError>where
E: EntityKind<Canister = C>,
pub fn replace_view<E>(
&self,
view: E::ViewType,
) -> Result<E::ViewType, InternalError>where
E: EntityKind<Canister = C>,
Replace an existing view or insert it if it does not yet exist.
Sourcepub fn update_view<E>(
&self,
view: E::ViewType,
) -> Result<E::ViewType, InternalError>where
E: EntityKind<Canister = C>,
pub fn update_view<E>(
&self,
view: E::ViewType,
) -> Result<E::ViewType, InternalError>where
E: EntityKind<Canister = C>,
Partially update an existing view.