Skip to main content

TransactionScope

Struct TransactionScope 

Source
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,

Source

pub fn context(&self) -> &'context UserContext

The runtime context that owns metadata, policy, telemetry and audit configuration for this transaction.

Source

pub fn entity_data_service( &self, entity: impl Into<String>, ) -> Result<EntityDataService<'_, E::Tx<'context>>, ContextError>
where E::Tx<'context>: QueryExecutor + MutationExecutor + Send + Sync,

Build an entity data service that is guaranteed to use this transaction.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'context, E> !Freeze for TransactionScope<'context, E>

§

impl<'context, E> !RefUnwindSafe for TransactionScope<'context, E>

§

impl<'context, E> !UnwindSafe for TransactionScope<'context, E>

§

impl<'context, E> Send for TransactionScope<'context, E>
where Option<<E as TransactionExecutor>::Tx<'context>>: Send,

§

impl<'context, E> Sync for TransactionScope<'context, E>
where Option<<E as TransactionExecutor>::Tx<'context>>: Sync,

§

impl<'context, E> Unpin for TransactionScope<'context, E>
where Option<<E as TransactionExecutor>::Tx<'context>>: Unpin,

§

impl<'context, E> UnsafeUnpin for TransactionScope<'context, E>
where Option<<E as TransactionExecutor>::Tx<'context>>: 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> 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, 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.