[−][src]Struct sqlx_core::transaction::Transaction
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]
C: Connection,
pub async fn begin(self) -> Result<Transaction<Transaction<C>>>
[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>
[src]
Commits the current transaction or save point. Returns the inner connection or transaction.
pub async fn rollback(__arg0: Self) -> Result<C>
[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]
C: Connection,
fn close(self) -> BoxFuture<'static, Result<()>>
[src]
fn ping(&mut self) -> BoxFuture<Result<()>>
[src]
fn begin(self) -> BoxFuture<'static, Result<Transaction<Self>>> where
Self: Sized,
[src]
Self: Sized,
impl<C> Deref for Transaction<C> where
C: Connection,
[src]
C: Connection,
impl<C> DerefMut for Transaction<C> where
C: Connection,
[src]
C: Connection,
impl<C> Drop for Transaction<C> where
C: Connection,
[src]
C: Connection,
impl<DB, C> Executor for Transaction<C> where
DB: Database,
C: Connection<Database = DB>,
[src]
DB: Database,
C: Connection<Database = DB>,
type Database = C::Database
The specific database that this type is implemented for.
fn execute<'e, 'q: 'e, 'c: 'e, E: 'e>(
&'c mut self,
query: E
) -> BoxFuture<'e, Result<u64>> where
E: Execute<'q, Self::Database>,
[src]
&'c mut self,
query: E
) -> BoxFuture<'e, Result<u64>> where
E: Execute<'q, Self::Database>,
fn fetch<'e, 'q, E>(
&'e mut self,
query: E
) -> <Self::Database as HasCursor<'e, 'q>>::Cursor where
E: Execute<'q, Self::Database>,
[src]
&'e mut self,
query: E
) -> <Self::Database as HasCursor<'e, 'q>>::Cursor where
E: Execute<'q, Self::Database>,
impl<'e, DB, C> RefExecutor<'e> for &'e mut Transaction<C> where
DB: Database,
C: Connection<Database = DB>,
[src]
DB: Database,
C: Connection<Database = DB>,
Auto Trait Implementations
impl<C> RefUnwindSafe for Transaction<C> where
C: RefUnwindSafe,
C: RefUnwindSafe,
impl<C> Send for Transaction<C>
impl<C> Sync for Transaction<C> where
C: Sync,
C: Sync,
impl<C> Unpin for Transaction<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for Transaction<C> where
C: UnwindSafe,
C: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,