pub trait TransactionTrait {
type Transaction: ConnectionTrait + TransactionTrait<Transaction = Self::Transaction> + TransactionSession;
// Required methods
fn begin(&self) -> Result<Self::Transaction, DbErr>;
fn begin_with_config(
&self,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<Self::Transaction, DbErr>;
fn begin_with_options(
&self,
options: TransactionOptions,
) -> Result<Self::Transaction, DbErr>;
fn transaction<F, T, E>(
&self,
callback: F,
) -> Result<T, TransactionError<E>>
where F: for<'c> FnOnce(&'c Self::Transaction) -> Result<T, E>,
E: Display + Debug;
fn transaction_with_config<F, T, E>(
&self,
callback: F,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<T, TransactionError<E>>
where F: for<'c> FnOnce(&'c Self::Transaction) -> Result<T, E>,
E: Display + Debug;
}Expand description
Begin a database transaction.
Implemented by DatabaseConnection and
DatabaseTransaction (allowing nested
transactions via SAVEPOINTs). Use begin for a manually
managed transaction, or transaction for a closure
that auto-commits on Ok and rolls back on Err.
Self::Transaction must be a fixed point — its own transaction type is
itself — because the ActiveModelEx mutation methods recurse through it
(see https://github.com/SeaQL/sea-orm/issues/3147).
Required Associated Types§
Sourcetype Transaction: ConnectionTrait + TransactionTrait<Transaction = Self::Transaction> + TransactionSession
type Transaction: ConnectionTrait + TransactionTrait<Transaction = Self::Transaction> + TransactionSession
The concrete type for the transaction
Required Methods§
Sourcefn begin(&self) -> Result<Self::Transaction, DbErr>
fn begin(&self) -> Result<Self::Transaction, DbErr>
Execute SQL BEGIN transaction.
Returns a Transaction that can be committed or rolled back
Sourcefn begin_with_config(
&self,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<Self::Transaction, DbErr>
fn begin_with_config( &self, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Result<Self::Transaction, DbErr>
Execute SQL BEGIN transaction with isolation level and/or access mode.
Returns a Transaction that can be committed or rolled back
Sourcefn begin_with_options(
&self,
options: TransactionOptions,
) -> Result<Self::Transaction, DbErr>
fn begin_with_options( &self, options: TransactionOptions, ) -> Result<Self::Transaction, DbErr>
Execute SQL BEGIN transaction with isolation level and/or access mode.
Returns a Transaction that can be committed or rolled back
Sourcefn transaction<F, T, E>(&self, callback: F) -> Result<T, TransactionError<E>>
fn transaction<F, T, E>(&self, callback: F) -> Result<T, TransactionError<E>>
Execute the function inside a transaction. If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
Sourcefn transaction_with_config<F, T, E>(
&self,
callback: F,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<T, TransactionError<E>>
fn transaction_with_config<F, T, E>( &self, callback: F, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Result<T, TransactionError<E>>
Execute the function inside a transaction with isolation level and/or access mode. If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl TransactionTrait for DatabaseExecutor<'_>
impl TransactionTrait for DatabaseExecutor<'_>
Source§impl TransactionTrait for RestrictedConnection
Available on crate feature rbac only.
impl TransactionTrait for RestrictedConnection
rbac only.Source§impl TransactionTrait for RestrictedTransaction
Available on crate feature rbac only.
impl TransactionTrait for RestrictedTransaction
rbac only.