pub struct DbSession<C: CanisterKind> { /* private fields */ }Expand description
DbSession
Session-scoped database handle with policy (debug, metrics) and execution routing.
Implementations§
Source§impl<C: CanisterKind> DbSession<C>
impl<C: CanisterKind> DbSession<C>
Sourcepub fn execute_query<E>(
&self,
query: &Query<E>,
) -> Result<EntityResponse<E>, QueryError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn execute_query<E>(
&self,
query: &Query<E>,
) -> Result<EntityResponse<E>, QueryError>where
E: PersistedRow<Canister = C> + EntityValue,
Execute one scalar load/delete query and return materialized response rows.
Sourcepub fn trace_query<E>(
&self,
query: &Query<E>,
) -> Result<QueryTracePlan, QueryError>where
E: EntityKind<Canister = C>,
pub fn trace_query<E>(
&self,
query: &Query<E>,
) -> Result<QueryTracePlan, QueryError>where
E: EntityKind<Canister = C>,
Build one trace payload for a query without executing it.
This lightweight surface is intended for developer diagnostics: plan hash, access strategy summary, and planner/executor route shape.
Source§impl<C: CanisterKind> DbSession<C>
impl<C: CanisterKind> DbSession<C>
Sourcepub fn execute_sql_query<E>(
&self,
sql: &str,
) -> Result<SqlStatementResult, QueryError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn execute_sql_query<E>(
&self,
sql: &str,
) -> Result<SqlStatementResult, QueryError>where
E: PersistedRow<Canister = C> + EntityValue,
Execute one single-entity reduced SQL query or introspection statement.
This surface stays hard-bound to E, rejects state-changing SQL, and
returns SQL-shaped statement output instead of typed entities.
Sourcepub fn execute_sql_update<E>(
&self,
sql: &str,
) -> Result<SqlStatementResult, QueryError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn execute_sql_update<E>(
&self,
sql: &str,
) -> Result<SqlStatementResult, QueryError>where
E: PersistedRow<Canister = C> + EntityValue,
Execute one single-entity reduced SQL mutation statement.
This surface stays hard-bound to E, rejects read-only SQL, and
returns SQL-shaped mutation output such as counts or RETURNING rows.
Source§impl<C: CanisterKind> DbSession<C>
impl<C: CanisterKind> DbSession<C>
Sourcepub fn insert<E>(&self, entity: E) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn insert<E>(&self, entity: E) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Insert one entity row.
Sourcepub fn create<I>(&self, input: I) -> Result<I::Entity, InternalError>
pub fn create<I>(&self, input: I) -> Result<I::Entity, InternalError>
Insert one authored typed input.
Sourcepub fn insert_many_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn insert_many_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Insert a single-entity-type batch atomically in one commit window.
If any item fails pre-commit validation, no row in the batch is persisted.
This API is not a multi-entity transaction surface.
Sourcepub fn insert_many_non_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn insert_many_non_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Insert a batch with explicitly non-atomic semantics.
WARNING: fail-fast and non-atomic. Earlier inserts may commit before an error.
Sourcepub fn replace<E>(&self, entity: E) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn replace<E>(&self, entity: E) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Replace one existing entity row.
Sourcepub fn mutate_structural<E>(
&self,
key: E::Key,
patch: UpdatePatch,
mode: MutationMode,
) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn mutate_structural<E>(
&self,
key: E::Key,
patch: UpdatePatch,
mode: MutationMode,
) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Apply one structural mutation under one explicit write-mode contract.
This is the public core session boundary for structural writes: callers provide the key, field patch, and intended mutation mode, and the session routes that through the shared structural mutation pipeline.
Sourcepub fn replace_many_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn replace_many_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Replace a single-entity-type batch atomically in one commit window.
If any item fails pre-commit validation, no row in the batch is persisted.
This API is not a multi-entity transaction surface.
Sourcepub fn replace_many_non_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn replace_many_non_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Replace a batch with explicitly non-atomic semantics.
WARNING: fail-fast and non-atomic. Earlier replaces may commit before an error.
Sourcepub fn update<E>(&self, entity: E) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn update<E>(&self, entity: E) -> Result<E, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Update one existing entity row.
Sourcepub fn update_many_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn update_many_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Update a single-entity-type batch atomically in one commit window.
If any item fails pre-commit validation, no row in the batch is persisted.
This API is not a multi-entity transaction surface.
Sourcepub fn update_many_non_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
pub fn update_many_non_atomic<E>(
&self,
entities: impl IntoIterator<Item = E>,
) -> Result<WriteBatchResponse<E>, InternalError>where
E: PersistedRow<Canister = C> + EntityValue,
Update a batch with explicitly non-atomic semantics.
WARNING: fail-fast and non-atomic. Earlier updates may commit before an error.
Source§impl<C: CanisterKind> DbSession<C>
impl<C: CanisterKind> DbSession<C>
Sourcepub const fn new_with_hooks(
store: &'static LocalKey<StoreRegistry>,
entity_runtime_hooks: &'static [EntityRuntimeHooks<C>],
) -> Self
pub const fn new_with_hooks( store: &'static LocalKey<StoreRegistry>, entity_runtime_hooks: &'static [EntityRuntimeHooks<C>], ) -> Self
Construct one session facade from store registry and runtime hooks.
Sourcepub const fn metrics_sink(self, sink: &'static dyn MetricsSink) -> Self
pub const fn metrics_sink(self, sink: &'static dyn MetricsSink) -> Self
Attach one metrics sink for all session-executed operations.
Sourcepub const fn load<E>(&self) -> FluentLoadQuery<'_, E>where
E: EntityKind<Canister = C>,
pub const fn load<E>(&self) -> FluentLoadQuery<'_, E>where
E: EntityKind<Canister = C>,
Start a fluent load query with default missing-row policy (Ignore).
Sourcepub const fn load_with_consistency<E>(
&self,
consistency: MissingRowPolicy,
) -> FluentLoadQuery<'_, E>where
E: EntityKind<Canister = C>,
pub const fn load_with_consistency<E>(
&self,
consistency: MissingRowPolicy,
) -> FluentLoadQuery<'_, E>where
E: EntityKind<Canister = C>,
Start a fluent load query with explicit missing-row policy.
Sourcepub fn delete<E>(&self) -> FluentDeleteQuery<'_, E>where
E: PersistedRow<Canister = C>,
pub fn delete<E>(&self) -> FluentDeleteQuery<'_, E>where
E: PersistedRow<Canister = C>,
Start a fluent delete query with default missing-row policy (Ignore).
Sourcepub fn delete_with_consistency<E>(
&self,
consistency: MissingRowPolicy,
) -> FluentDeleteQuery<'_, E>where
E: PersistedRow<Canister = C>,
pub fn delete_with_consistency<E>(
&self,
consistency: MissingRowPolicy,
) -> FluentDeleteQuery<'_, E>where
E: PersistedRow<Canister = C>,
Start a fluent delete query with explicit missing-row policy.
Sourcepub const fn select_one(&self) -> Value
pub const fn select_one(&self) -> Value
Return one constant scalar row equivalent to SQL SELECT 1.
This terminal bypasses query planning and access routing entirely.
Sourcepub fn show_indexes<E>(&self) -> Vec<String>where
E: EntityKind<Canister = C>,
pub fn show_indexes<E>(&self) -> Vec<String>where
E: EntityKind<Canister = C>,
Return one stable, human-readable index listing for the entity schema.
Output format mirrors SQL-style introspection:
PRIMARY KEY (field)INDEX name (field_a, field_b)UNIQUE INDEX name (field_a, field_b)
Sourcepub fn show_indexes_for_model(&self, model: &'static EntityModel) -> Vec<String>
pub fn show_indexes_for_model(&self, model: &'static EntityModel) -> Vec<String>
Return one stable, human-readable index listing for one schema model.
This model-only helper is schema-owned and intentionally does not attach runtime lifecycle state because it does not carry store placement context.
Sourcepub fn show_columns<E>(&self) -> Vec<EntityFieldDescription>where
E: EntityKind<Canister = C>,
pub fn show_columns<E>(&self) -> Vec<EntityFieldDescription>where
E: EntityKind<Canister = C>,
Return one stable list of field descriptors for the entity schema.
Sourcepub fn show_columns_for_model(
&self,
model: &'static EntityModel,
) -> Vec<EntityFieldDescription>
pub fn show_columns_for_model( &self, model: &'static EntityModel, ) -> Vec<EntityFieldDescription>
Return one stable list of field descriptors for one schema model.
Sourcepub fn show_entities(&self) -> Vec<String>
pub fn show_entities(&self) -> Vec<String>
Return one stable list of runtime-registered entity names.
Sourcepub fn show_tables(&self) -> Vec<String>
pub fn show_tables(&self) -> Vec<String>
Return one stable list of runtime-registered entity names.
SHOW TABLES is only an alias for SHOW ENTITIES, so the typed
metadata surface keeps the same alias relationship.
Sourcepub fn describe_entity<E>(&self) -> EntitySchemaDescriptionwhere
E: EntityKind<Canister = C>,
pub fn describe_entity<E>(&self) -> EntitySchemaDescriptionwhere
E: EntityKind<Canister = C>,
Return one structured schema description for the entity.
This is a typed DESCRIBE-style introspection surface consumed by
developer tooling and pre-EXPLAIN debugging.
Sourcepub fn describe_entity_model(
&self,
model: &'static EntityModel,
) -> EntitySchemaDescription
pub fn describe_entity_model( &self, model: &'static EntityModel, ) -> EntitySchemaDescription
Return one structured schema description for one schema model.
Sourcepub fn storage_report(
&self,
name_to_path: &[(&'static str, &'static str)],
) -> Result<StorageReport, InternalError>
pub fn storage_report( &self, name_to_path: &[(&'static str, &'static str)], ) -> Result<StorageReport, InternalError>
Build one point-in-time storage report for observability endpoints.
Sourcepub fn storage_report_default(&self) -> Result<StorageReport, InternalError>
pub fn storage_report_default(&self) -> Result<StorageReport, InternalError>
Build one point-in-time storage report using default entity-path labels.
Sourcepub fn integrity_report(&self) -> Result<IntegrityReport, InternalError>
pub fn integrity_report(&self) -> Result<IntegrityReport, InternalError>
Build one point-in-time integrity scan report for observability endpoints.
Sourcepub fn execute_migration_plan(
&self,
plan: &MigrationPlan,
max_steps: usize,
) -> Result<MigrationRunOutcome, InternalError>
pub fn execute_migration_plan( &self, plan: &MigrationPlan, max_steps: usize, ) -> Result<MigrationRunOutcome, InternalError>
Execute one bounded migration run with durable internal cursor state.
Migration progress is persisted internally so upgrades/restarts can resume from the last successful step without external cursor ownership.