pub struct TransactionScope<'context, E>where
E: TransactionExecutor + 'context,{ /* private fields */ }Expand description
A real provider transaction bound to a UserContext.
All work must be performed through this object. This makes it impossible to accidentally open a transaction and then execute against the context’s non-transactional executor, which was the defect in the former placeholder API.
Implementations§
Source§impl<'context, E> TransactionScope<'context, E>where
E: TransactionExecutor + 'context,
impl<'context, E> TransactionScope<'context, E>where
E: TransactionExecutor + 'context,
Sourcepub fn context(&self) -> &'context UserContext
pub fn context(&self) -> &'context UserContext
The runtime context that owns metadata, policy, telemetry and audit configuration for this transaction.
Sourcepub fn entity_data_service(
&self,
entity: impl Into<String>,
) -> Result<EntityDataService<'_, E::Tx<'context>>, ContextError>
pub fn entity_data_service( &self, entity: impl Into<String>, ) -> Result<EntityDataService<'_, E::Tx<'context>>, ContextError>
Build an entity data service that is guaranteed to use this transaction.
Sourcepub async fn query(
&self,
request: QueryRequest,
) -> Result<QueryResult, RuntimeError>where
E::Tx<'context>: QueryExecutor,
pub async fn query(
&self,
request: QueryRequest,
) -> Result<QueryResult, RuntimeError>where
E::Tx<'context>: QueryExecutor,
Execute a provider-neutral query on the transaction-owned connection.
Sourcepub async fn mutate(
&self,
request: MutationRequest,
) -> Result<MutationResult, RuntimeError>where
E::Tx<'context>: MutationExecutor,
pub async fn mutate(
&self,
request: MutationRequest,
) -> Result<MutationResult, RuntimeError>where
E::Tx<'context>: MutationExecutor,
Execute a provider-neutral mutation on the transaction-owned connection.
Sourcepub async fn save_audited<T>(
&self,
audited: Audited<T>,
) -> Result<T, RuntimeError>where
T: LedgerEntity + Send + 'static,
E::Tx<'context>: QueryExecutor + MutationExecutor + Send + Sync,
pub async fn save_audited<T>(
&self,
audited: Audited<T>,
) -> Result<T, RuntimeError>where
T: LedgerEntity + Send + 'static,
E::Tx<'context>: QueryExecutor + MutationExecutor + Send + Sync,
Save one audited generated entity through this transaction.
Its mutation ledger remains pending until the enclosing scope commits, so a later failure can roll back the database without losing retryable in-memory mutation intent.
Sourcepub async fn execute<T, F>(self, operation: F) -> Result<T, RuntimeError>where
E::Tx<'context>: Send + Sync,
F: for<'scope> FnOnce(&'scope TransactionScope<'context, E>) -> Pin<Box<dyn Future<Output = Result<T, RuntimeError>> + 'scope>>,
pub async fn execute<T, F>(self, operation: F) -> Result<T, RuntimeError>where
E::Tx<'context>: Send + Sync,
F: for<'scope> FnOnce(&'scope TransactionScope<'context, E>) -> Pin<Box<dyn Future<Output = Result<T, RuntimeError>> + 'scope>>,
Run a callback and complete this transaction deterministically.