pub struct DatabaseTransaction { /* private fields */ }Expand description
Defines a database transaction, whether it is an open transaction and the type of backend to use. Under the hood, a Transaction is just a wrapper for a connection where START TRANSACTION has been executed.
Implementations§
Source§impl DatabaseTransaction
impl DatabaseTransaction
Sourcepub async fn transaction_async<F, T, E>(
&self,
callback: F,
) -> Result<T, TransactionError<E>>where
F: for<'c> AsyncFnOnce(&'c DatabaseTransaction) -> Result<T, E> + Send,
T: Send,
E: Display + Debug + Send,
pub async fn transaction_async<F, T, E>(
&self,
callback: F,
) -> Result<T, TransactionError<E>>where
F: for<'c> AsyncFnOnce(&'c DatabaseTransaction) -> Result<T, E> + Send,
T: Send,
E: Display + Debug + Send,
Execute the function inside a transaction. If the function returns an error, the transaction will be rolled back. Otherwise, the transaction will be committed.
Sourcepub async fn transaction_with_config_async<F, T, E>(
&self,
callback: F,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<T, TransactionError<E>>where
F: for<'c> AsyncFnOnce(&'c DatabaseTransaction) -> Result<T, E> + Send,
T: Send,
E: Display + Debug + Send,
pub async fn transaction_with_config_async<F, T, E>(
&self,
callback: F,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<T, TransactionError<E>>where
F: for<'c> AsyncFnOnce(&'c DatabaseTransaction) -> Result<T, E> + Send,
T: Send,
E: Display + Debug + Send,
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. Otherwise, the transaction will be committed.
Trait Implementations§
Source§impl Connection for DatabaseTransaction
impl Connection for DatabaseTransaction
fn query_all<'life0, 'async_trait>(
&'life0 self,
select: SelectStatement,
) -> Pin<Box<dyn Future<Output = Result<Vec<SqlxRow>, Error>> + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn query_all_raw<'life0, 'async_trait>(
&'life0 self,
sql: String,
) -> Pin<Box<dyn Future<Output = Result<Vec<SqlxRow>, Error>> + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
Source§impl ConnectionTrait for DatabaseTransaction
impl ConnectionTrait for DatabaseTransaction
Source§fn get_database_backend(&self) -> DatabaseBackend
fn get_database_backend(&self) -> DatabaseBackend
Source§fn execute_raw<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn execute_raw<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
Source§fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DatabaseTransaction: 'async_trait,
fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DatabaseTransaction: 'async_trait,
Source§fn query_one_raw<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn query_one_raw<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
QueryResultSource§fn query_all_raw<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn query_all_raw<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
QueryResultSource§fn execute<'life0, 'life1, 'async_trait, S>(
&'life0 self,
stmt: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
S: 'async_trait + StatementBuilder,
Self: 'async_trait,
fn execute<'life0, 'life1, 'async_trait, S>(
&'life0 self,
stmt: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
S: 'async_trait + StatementBuilder,
Self: 'async_trait,
Source§fn query_one<'life0, 'life1, 'async_trait, S>(
&'life0 self,
stmt: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
S: 'async_trait + StatementBuilder,
Self: 'async_trait,
fn query_one<'life0, 'life1, 'async_trait, S>(
&'life0 self,
stmt: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
S: 'async_trait + StatementBuilder,
Self: 'async_trait,
QueryResultSource§fn query_all<'life0, 'life1, 'async_trait, S>(
&'life0 self,
stmt: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
S: 'async_trait + StatementBuilder,
Self: 'async_trait,
fn query_all<'life0, 'life1, 'async_trait, S>(
&'life0 self,
stmt: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
S: 'async_trait + StatementBuilder,
Self: 'async_trait,
QueryResultSource§fn support_returning(&self) -> bool
fn support_returning(&self) -> bool
RETURNING syntax on insert and updateSource§fn is_mock_connection(&self) -> bool
fn is_mock_connection(&self) -> bool
Source§impl Debug for DatabaseTransaction
impl Debug for DatabaseTransaction
Source§impl Drop for DatabaseTransaction
impl Drop for DatabaseTransaction
Source§impl<'c> From<&'c DatabaseTransaction> for DatabaseExecutor<'c>
impl<'c> From<&'c DatabaseTransaction> for DatabaseExecutor<'c>
Source§fn from(trans: &'c DatabaseTransaction) -> DatabaseExecutor<'c>
fn from(trans: &'c DatabaseTransaction) -> DatabaseExecutor<'c>
Source§impl<'c> IntoDatabaseExecutor<'c> for &'c DatabaseTransaction
impl<'c> IntoDatabaseExecutor<'c> for &'c DatabaseTransaction
Source§fn into_database_executor(self) -> DatabaseExecutor<'c>
fn into_database_executor(self) -> DatabaseExecutor<'c>
DatabaseExecutorSource§impl IntoDatabaseExecutor<'static> for DatabaseTransaction
impl IntoDatabaseExecutor<'static> for DatabaseTransaction
Source§fn into_database_executor(self) -> DatabaseExecutor<'static>
fn into_database_executor(self) -> DatabaseExecutor<'static>
DatabaseExecutorSource§impl StreamTrait for DatabaseTransaction
impl StreamTrait for DatabaseTransaction
Source§type Stream<'a> = TransactionStream<'a>
type Stream<'a> = TransactionStream<'a>
Source§fn get_database_backend(&self) -> DatabaseBackend
fn get_database_backend(&self) -> DatabaseBackend
Source§fn stream_raw<'a>(
&'a self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<<DatabaseTransaction as StreamTrait>::Stream<'a>, DbErr>> + Send + 'a>>
fn stream_raw<'a>( &'a self, stmt: Statement, ) -> Pin<Box<dyn Future<Output = Result<<DatabaseTransaction as StreamTrait>::Stream<'a>, DbErr>> + Send + 'a>>
Source§impl TransactionSession for DatabaseTransaction
impl TransactionSession for DatabaseTransaction
Source§impl TransactionTrait for DatabaseTransaction
impl TransactionTrait for DatabaseTransaction
Source§fn transaction<'life0, 'async_trait, F, T, E>(
&'life0 self,
_callback: F,
) -> Pin<Box<dyn Future<Output = Result<T, TransactionError<E>>> + Send + 'async_trait>>
fn transaction<'life0, 'async_trait, F, T, E>( &'life0 self, _callback: F, ) -> Pin<Box<dyn Future<Output = Result<T, TransactionError<E>>> + Send + 'async_trait>>
Execute the async function inside a transaction. If the function returns an error, the transaction will be rolled back. Otherwise, the transaction will be committed.
Source§fn transaction_with_config<'life0, 'async_trait, F, T, E>(
&'life0 self,
_callback: F,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Pin<Box<dyn Future<Output = Result<T, TransactionError<E>>> + Send + 'async_trait>>
fn transaction_with_config<'life0, 'async_trait, F, T, E>( &'life0 self, _callback: F, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Pin<Box<dyn Future<Output = Result<T, TransactionError<E>>> + Send + 'async_trait>>
Execute the async function inside a transaction. If the function returns an error, the transaction will be rolled back. Otherwise, the transaction will be committed.
Source§type Transaction = DatabaseTransaction
type Transaction = DatabaseTransaction
Source§fn begin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn begin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
BEGIN transaction.
Returns a Transaction that can be committed or rolled backSource§fn begin_with_config<'life0, 'async_trait>(
&'life0 self,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn begin_with_config<'life0, 'async_trait>(
&'life0 self,
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
BEGIN transaction with isolation level and/or access mode.
Returns a Transaction that can be committed or rolled backSource§fn begin_with_options<'life0, 'async_trait>(
&'life0 self,
options: TransactionOptions,
) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
fn begin_with_options<'life0, 'async_trait>(
&'life0 self,
options: TransactionOptions,
) -> Pin<Box<dyn Future<Output = Result<DatabaseTransaction, DbErr>> + Send + 'async_trait>>where
'life0: 'async_trait,
DatabaseTransaction: 'async_trait,
BEGIN transaction with isolation level and/or access mode.
Returns a Transaction that can be committed or rolled backAuto Trait Implementations§
impl !RefUnwindSafe for DatabaseTransaction
impl !UnwindSafe for DatabaseTransaction
impl Freeze for DatabaseTransaction
impl Send for DatabaseTransaction
impl Sync for DatabaseTransaction
impl Unpin for DatabaseTransaction
impl UnsafeUnpin for DatabaseTransaction
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
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> ⓘ
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> ⓘ
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