#[non_exhaustive]pub struct SqlxOpStoreTx<DB: Database> { /* private fields */ }Expand description
A SqlxOpStore scoped to one open sqlx transaction — every store
method called on it runs inside that transaction, and nothing lands until
commit.
Obtain one from [SqlxOpStore::begin_tx]. Dropping it without committing
rolls back, so an early ? in the middle of a composed unit of work
cannot leave a half-written state behind.
§Composing with the host application’s own writes
This is the point of the type. as_mut hands back the
live connection, so the application’s own statements and the store’s run
in the same transaction and commit or roll back together:
let mut tx = store.begin_tx().await?;
sqlx::query("INSERT INTO app_users (id, email) VALUES (?1, ?2)")
.bind(&user_id)
.bind(&email)
.execute(tx.as_mut())
.await?;
tx.store_token(refresh_token).await?; // same transaction
tx.commit().await?; // both, or neitherReaching the native connection is deliberately an inherent method rather
than something on the OpStoreTransaction
trait: the host’s own queries are written against a concrete driver, so
there is nothing for a backend-agnostic trait to usefully return here.
Keeping it off the trait is what lets the trait stay dyn-compatible.
Implementations§
Source§impl<DB: Database> SqlxOpStoreTx<DB>
impl<DB: Database> SqlxOpStoreTx<DB>
Sourcepub async fn commit(self) -> Result<(), StoreError>
pub async fn commit(self) -> Result<(), StoreError>
Commit, making every write in this transaction durable at once.
Sourcepub async fn rollback(self) -> Result<(), StoreError>
pub async fn rollback(self) -> Result<(), StoreError>
Roll back, discarding every write in this transaction.
Dropping does this too; calling it explicitly is how a caller gets to
see a rollback failure rather than have Drop swallow it.
Trait Implementations§
Source§impl<DB: Database> AsMut<<DB as Database>::Connection> for SqlxOpStoreTx<DB>
The live connection inside this transaction, for the host application’s own
statements — tx.as_mut(), exactly as it reads on a bare
sqlx::Transaction, so a caller’s queries look the way they would
anywhere else in their code.
impl<DB: Database> AsMut<<DB as Database>::Connection> for SqlxOpStoreTx<DB>
The live connection inside this transaction, for the host application’s own
statements — tx.as_mut(), exactly as it reads on a bare
sqlx::Transaction, so a caller’s queries look the way they would
anywhere else in their code.
Source§fn as_mut(&mut self) -> &mut DB::Connection
fn as_mut(&mut self) -> &mut DB::Connection
Auto Trait Implementations§
impl<DB> !RefUnwindSafe for SqlxOpStoreTx<DB>
impl<DB> !UnwindSafe for SqlxOpStoreTx<DB>
impl<DB> Freeze for SqlxOpStoreTx<DB>where
Transaction<'static, DB>: Freeze,
impl<DB> Send for SqlxOpStoreTx<DB>where
Transaction<'static, DB>: Send,
impl<DB> Sync for SqlxOpStoreTx<DB>where
Transaction<'static, DB>: Sync,
impl<DB> Unpin for SqlxOpStoreTx<DB>where
Transaction<'static, DB>: Unpin,
impl<DB> UnsafeUnpin for SqlxOpStoreTx<DB>where
Transaction<'static, DB>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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