pub struct TransactionContext { /* private fields */ }Available on crate feature
postgres only.Expand description
Active transaction context with repository access.
This struct holds the database transaction and provides access to entity repositories via extension traits generated by the macro.
§Automatic Rollback
If dropped without explicit commit, the transaction is automatically rolled back via the underlying database transaction’s Drop impl.
§Accessing Repositories
Each entity with #[entity(transactions)] generates an extension trait
that adds an accessor method:
ⓘ
// For entity BankAccount, use:
ctx.bank_accounts().find_by_id(id).await?;
ctx.bank_accounts().create(dto).await?;
ctx.bank_accounts().update(id, dto).await?;Implementations§
Source§impl TransactionContext
impl TransactionContext
Sourcepub fn transaction(&mut self) -> &mut Transaction<'static, Postgres>
pub fn transaction(&mut self) -> &mut Transaction<'static, Postgres>
Get mutable reference to the underlying transaction.
Use this for custom queries within the transaction or for repository adapters to execute queries.
Auto Trait Implementations§
impl Freeze for TransactionContext
impl !RefUnwindSafe for TransactionContext
impl Send for TransactionContext
impl Sync for TransactionContext
impl Unpin for TransactionContext
impl !UnwindSafe for TransactionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more