Transaction

Struct Transaction 

Source
pub struct Transaction<'c, DB>
where DB: Database,
{ /* private fields */ }
Expand description

SQLx re-exports for other projects An in-progress database transaction or savepoint.

A transaction starts with a call to Pool::begin or Connection::begin.

A transaction should end with a call to commit or rollback. 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.

A savepoint is a special mark inside a transaction that allows all commands that are executed after it was established to be rolled back, restoring the transaction state to what it was at the time of the savepoint.

A transaction can be used as an Executor when performing queries:

let mut tx = conn.begin().await?;

let result = sqlx::query("DELETE FROM \"testcases\" WHERE id = $1")
    .bind(id)
    .execute(&mut *tx)
    .await?
    .rows_affected();

tx.commit().await

Implementations§

Source§

impl<'c, DB> Transaction<'c, DB>
where DB: Database,

Source

pub async fn commit(self) -> Result<(), Error>

Commits this transaction or savepoint.

Source

pub async fn rollback(self) -> Result<(), Error>

Aborts this transaction or savepoint.

Trait Implementations§

Source§

impl<'c, 't, DB> Acquire<'t> for &'t mut Transaction<'c, DB>
where DB: Database,

Source§

type Database = DB

Source§

type Connection = &'t mut <DB as Database>::Connection

Source§

fn acquire( self, ) -> Pin<Box<dyn Future<Output = Result<<&'t mut Transaction<'c, DB> as Acquire<'t>>::Connection, Error>> + Send + 't>>

Source§

fn begin( self, ) -> Pin<Box<dyn Future<Output = Result<Transaction<'t, DB>, Error>> + Send + 't>>

Source§

impl<'c, DB> AsMut<<DB as Database>::Connection> for Transaction<'c, DB>
where DB: Database,

Source§

fn as_mut(&mut self) -> &mut <DB as Database>::Connection

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<'c, DB> Debug for Transaction<'c, DB>
where DB: Database,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'c, DB> Deref for Transaction<'c, DB>
where DB: Database,

Source§

type Target = <DB as Database>::Connection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Transaction<'c, DB> as Deref>::Target

Dereferences the value.
Source§

impl<'c, DB> DerefMut for Transaction<'c, DB>
where DB: Database,

Source§

fn deref_mut(&mut self) -> &mut <Transaction<'c, DB> as Deref>::Target

Mutably dereferences the value.
Source§

impl<'c, DB> Drop for Transaction<'c, DB>
where DB: Database,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'c, DB> Freeze for Transaction<'c, DB>
where <DB as Database>::Connection: Freeze,

§

impl<'c, DB> !RefUnwindSafe for Transaction<'c, DB>

§

impl<'c, DB> Send for Transaction<'c, DB>

§

impl<'c, DB> Sync for Transaction<'c, DB>
where <DB as Database>::Connection: Sync,

§

impl<'c, DB> Unpin for Transaction<'c, DB>
where <DB as Database>::Connection: Unpin,

§

impl<'c, DB> !UnwindSafe for Transaction<'c, DB>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<K, V, T> Expiry<K, V> for T
where T: Deref<Target = dyn Expiry<K, V> + Sync + Send>,

Source§

fn expire_after_create( &self, key: &K, value: &V, created_at: Instant, ) -> Option<Duration>

Specifies that the entry should be automatically removed from the cache once the duration has elapsed after the entry’s creation. This method is called for cache write methods such as insert and get_with but only when the key was not present in the cache. Read more
Source§

fn expire_after_read( &self, key: &K, value: &V, read_at: Instant, duration_until_expiry: Option<Duration>, last_modified_at: Instant, ) -> Option<Duration>

Specifies that the entry should be automatically removed from the cache once the duration has elapsed after its last read. This method is called for cache read methods such as get and get_with but only when the key is present in the cache. Read more
Source§

fn expire_after_update( &self, key: &K, value: &V, updated_at: Instant, duration_until_expiry: Option<Duration>, ) -> Option<Duration>

Specifies that the entry should be automatically removed from the cache once the duration has elapsed after the replacement of its value. This method is called for cache write methods such as insert but only when the key is already present in the cache. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,