[][src]Struct sqlx::Transaction

#[must_use = "transaction rolls back if not explicitly `.commit()`ed"]pub struct Transaction<C> where
    C: Connection
{ /* fields omitted */ }

Represents an in-progress database transaction.

A transaction ends with a call to commit or rollback in which the wrapped connection ( or outer transaction) is returned. If neither are called before the transaction goes out-of-scope, rollback is called. In other words, rollback is called on drop if the transaction is still in-progress.

ⓘThis example is not tested
// Acquire a new connection and immediately begin a transaction
let mut tx = pool.begin().await?;

sqlx::query("INSERT INTO articles (slug) VALUES ('this-is-a-slug')")
    .execute(&mut tx)
    // As we didn't fill in all the required fields in this INSERT,
    // this statement will fail. Since we used `?`, this function
    // will immediately return with the error which will cause
    // this transaction to be rolled back.
    .await?;

Methods

impl<C> Transaction<C> where
    C: Connection
[src]

pub async fn begin(self) -> Result<Transaction<Transaction<C>>, Error>[src]

Creates a new save point in the current transaction and returns a new Transaction object to manage its scope.

pub async fn commit(__arg0: Self) -> Result<C, Error>[src]

Commits the current transaction or save point. Returns the inner connection or transaction.

pub async fn rollback(__arg0: Self) -> Result<C, Error>[src]

Rollback the current transaction or save point. Returns the inner connection or transaction.

Trait Implementations

impl<C> Connection for Transaction<C> where
    C: Connection
[src]

impl<C> Deref for Transaction<C> where
    C: Connection
[src]

type Target = C

The resulting type after dereferencing.

impl<C> DerefMut for Transaction<C> where
    C: Connection
[src]

impl<C> Drop for Transaction<C> where
    C: Connection
[src]

impl<DB, C> Executor for Transaction<C> where
    C: Connection<Database = DB>,
    DB: Database
[src]

type Database = <C as Executor>::Database

The specific database that this type is implemented for.

impl<'e, DB, C> RefExecutor<'e> for &'e mut Transaction<C> where
    C: Connection<Database = DB>,
    DB: Database
[src]

type Database = DB

Auto Trait Implementations

impl<C> RefUnwindSafe for Transaction<C> where
    C: RefUnwindSafe

impl<C> Send for Transaction<C>

impl<C> Sync for Transaction<C> where
    C: Sync

impl<C> Unpin for Transaction<C> where
    C: Unpin

impl<C> UnwindSafe for Transaction<C> where
    C: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,