Skip to main content

TransactionTrait

Trait TransactionTrait 

Source
pub trait TransactionTrait: Send + Sync {
    // Required methods
    fn begin<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Transaction>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn begin_with_mode<'life0, 'async_trait>(
        &'life0 self,
        mode: TransactionMode,
    ) -> Pin<Box<dyn Future<Output = Result<Transaction>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn transaction<'life0, 'async_trait, F, T, E>(
        &'life0 self,
        callback: F,
    ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'async_trait>>
       where F: for<'c> FnOnce(&'c Transaction) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>> + Send + 'async_trait,
             T: Send + 'async_trait,
             E: From<Error> + Send + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Starts transactions.

Required Methods§

Source

fn begin<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Transaction>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Begins with BEGIN DEFERRED, or a savepoint when called on a transaction.

§Errors

Returns Error::Turso when the engine cannot start the transaction, and on Database Error::PoolTimeout when no connection is free within the acquire timeout.

Source

fn begin_with_mode<'life0, 'async_trait>( &'life0 self, mode: TransactionMode, ) -> Pin<Box<dyn Future<Output = Result<Transaction>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Begins with an explicit mode; the mode is ignored for nested transactions, which are always savepoints.

§Errors

Returns Error::Turso when the engine cannot start the transaction — with ErrorKind::Busy when an IMMEDIATE or EXCLUSIVE lock cannot be taken within the busy timeout — and on Database Error::PoolTimeout when no connection is free.

Provided Methods§

Source

fn transaction<'life0, 'async_trait, F, T, E>( &'life0 self, callback: F, ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'async_trait>>
where F: for<'c> FnOnce(&'c Transaction) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>> + Send + 'async_trait, T: Send + 'async_trait, E: From<Error> + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Runs callback inside a transaction, committing on Ok and rolling back on Err.

The callback receives &Transaction rather than owning it so that it cannot commit or roll back on its own and leave this method with a finished transaction.

§Errors

Returns the callback’s error after rolling back, or the driver error converted through E::from when beginning, committing or rolling back fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§