Skip to main content

Transaction

Trait Transaction 

Source
pub trait Transaction: Send + Sync {
    // Required methods
    fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 mut self,
        sql: &'life1 str,
        params: &'life2 [&'life3 dyn ToSqlValue],
    ) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 mut self,
        sql: &'life1 str,
        params: &'life2 [&'life3 dyn ToSqlValue],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn commit<'async_trait>(
        self: Box<Self>,
    ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn rollback<'async_trait>(
        self: Box<Self>,
    ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait;

    // Provided methods
    fn savepoint<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn release_savepoint<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn rollback_to_savepoint<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn query_stream<'a>(
        &'a mut self,
        sql: &'a str,
        params: &'a [&'a dyn ToSqlValue],
    ) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>> { ... }
}
Expand description

A database transaction obtained via Connection::transaction.

Dropping the transaction without calling commit will implicitly roll back any pending changes.

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, sql: &'life1 str, params: &'life2 [&'life3 dyn ToSqlValue], ) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute a DML/DDL statement within the transaction.

Source

fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, sql: &'life1 str, params: &'life2 [&'life3 dyn ToSqlValue], ) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute a SELECT statement within the transaction.

Source

fn commit<'async_trait>( self: Box<Self>, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,

Commit all changes made within this transaction.

Source

fn rollback<'async_trait>( self: Box<Self>, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,

Roll back all changes made within this transaction.

Provided Methods§

Source

fn savepoint<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a named savepoint within the transaction.

Savepoints allow nested rollback to a specific point without aborting the entire transaction. The name must be a valid SQL identifier (alphanumeric and underscores only; no spaces or special characters).

The default implementation returns an error. Backends that support savepoints (Postgres, MySQL) should override this.

Source

fn release_savepoint<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Release (discard) a named savepoint.

The default implementation returns an error.

Source

fn rollback_to_savepoint<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Roll back the transaction to the named savepoint, undoing all changes made after the savepoint was created without ending the transaction.

The default implementation returns an error.

Source

fn query_stream<'a>( &'a mut self, sql: &'a str, params: &'a [&'a dyn ToSqlValue], ) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>

Execute a SELECT within the transaction and return rows as an async stream.

Mirrors Connection::query_stream exactly: the default implementation materialises the full result via query then streams the rows one by one. Backends that support server-side cursors may override with incremental fetching.

This is a regular (non-async) method that returns Pin<Box<dyn Stream>> directly. The lifetime 'a ties both self and the SQL/params slices to the returned stream so the borrow checker enforces that self is not moved while the stream is live.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§