pub trait TransactionTrait {
type Transaction: ConnectionTrait + TransactionTrait + 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 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
Spawn database transaction
Required Associated Typesยง
Sourcetype Transaction: ConnectionTrait + TransactionTrait + TransactionSession
type Transaction: ConnectionTrait + TransactionTrait + 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 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", so this trait is not object safe.
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.