Skip to main content

Transaction

Trait Transaction 

Source
pub trait Transaction: Send {
    type Error: Error + Send + Sync + 'static;
    type Row: Row;
    type Nested<'a>: Transaction<Error = Self::Error, Row = Self::Row> + 'a
       where Self: 'a;

    // Required methods
    fn query(
        &self,
        sql: &str,
        params: &[&dyn ToSqlParam],
    ) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send;
    fn execute(
        &self,
        sql: &str,
        params: &[&dyn ToSqlParam],
    ) -> impl Future<Output = Result<u64, Self::Error>> + Send;
    fn transaction(
        &mut self,
    ) -> impl Future<Output = Result<Self::Nested<'_>, Self::Error>> + Send;
    fn commit(self) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn rollback(self) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
Expand description

Trait for a database transaction. Supports the same query/execute operations as Client, plus commit/rollback. Dropping without calling commit() should rollback the transaction.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Source

type Row: Row

Source

type Nested<'a>: Transaction<Error = Self::Error, Row = Self::Row> + 'a where Self: 'a

Required Methods§

Source

fn query( &self, sql: &str, params: &[&dyn ToSqlParam], ) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send

Execute a query that returns rows.

Source

fn execute( &self, sql: &str, params: &[&dyn ToSqlParam], ) -> impl Future<Output = Result<u64, Self::Error>> + Send

Execute a statement that returns the number of affected rows.

Source

fn transaction( &mut self, ) -> impl Future<Output = Result<Self::Nested<'_>, Self::Error>> + Send

Begin a nested transaction (savepoint).

Source

fn commit(self) -> impl Future<Output = Result<(), Self::Error>> + Send

Commit this transaction.

Source

fn rollback(self) -> impl Future<Output = Result<(), Self::Error>> + Send

Rollback this transaction.

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§