pub struct SqlxTransactionCompanion<C = PostcardCodec>where
C: CacheCodec,{ /* private fields */ }Expand description
SQLx transaction companion.
The companion begins a transaction, gives user code explicit access to the SQLx transaction and an invalidation collector, then either enqueues durable outbox rows before commit or applies local-only invalidation after commit.
Implementations§
Source§impl<C> SqlxTransactionCompanion<C>where
C: CacheCodec,
impl<C> SqlxTransactionCompanion<C>where
C: CacheCodec,
Sourcepub fn new(queries: DbCache<C>) -> Self
pub fn new(queries: DbCache<C>) -> Self
Create a companion for the given query cache namespace.
Sourcepub fn with_outbox(self, outbox: SqlxInvalidationOutbox) -> Self
pub fn with_outbox(self, outbox: SqlxInvalidationOutbox) -> Self
Attach a durable SQLx invalidation outbox.
Sourcepub fn diagnostics(&self) -> SqlxTransactionDiagnostics
pub fn diagnostics(&self) -> SqlxTransactionDiagnostics
Return transaction companion diagnostics.
Sourcepub async fn sqlite_durable<F, E>(
&self,
pool: &SqlitePool,
reason: impl Into<String>,
body: F,
) -> TransactionResult<SqlxTransactionReport, E>where
F: for<'tx> FnOnce(&'tx mut Transaction<'_, Sqlite>, &'tx mut InvalidationCollector) -> SqlxTransactionFuture<'tx, E> + Send,
E: Error + Send + Sync + 'static,
pub async fn sqlite_durable<F, E>(
&self,
pool: &SqlitePool,
reason: impl Into<String>,
body: F,
) -> TransactionResult<SqlxTransactionReport, E>where
F: for<'tx> FnOnce(&'tx mut Transaction<'_, Sqlite>, &'tx mut InvalidationCollector) -> SqlxTransactionFuture<'tx, E> + Send,
E: Error + Send + Sync + 'static,
Execute a SQLite transaction and enqueue invalidation intent before commit.
Sourcepub async fn sqlite_local<F, E>(
&self,
pool: &SqlitePool,
reason: impl Into<String>,
body: F,
) -> TransactionResult<SqlxTransactionReport, E>where
F: for<'tx> FnOnce(&'tx mut Transaction<'_, Sqlite>, &'tx mut InvalidationCollector) -> SqlxTransactionFuture<'tx, E> + Send,
E: Error + Send + Sync + 'static,
pub async fn sqlite_local<F, E>(
&self,
pool: &SqlitePool,
reason: impl Into<String>,
body: F,
) -> TransactionResult<SqlxTransactionReport, E>where
F: for<'tx> FnOnce(&'tx mut Transaction<'_, Sqlite>, &'tx mut InvalidationCollector) -> SqlxTransactionFuture<'tx, E> + Send,
E: Error + Send + Sync + 'static,
Execute a SQLite transaction and apply invalidation directly after commit.
This mode is intentionally non-durable. It is useful for local demos and
single-process tests, while production writes should use
SqlxTransactionCompanion::sqlite_durable.
Trait Implementations§
Source§impl<C> Clone for SqlxTransactionCompanion<C>where
C: CacheCodec,
impl<C> Clone for SqlxTransactionCompanion<C>where
C: CacheCodec,
Auto Trait Implementations§
impl<C = PostcardCodec> !RefUnwindSafe for SqlxTransactionCompanion<C>
impl<C = PostcardCodec> !UnwindSafe for SqlxTransactionCompanion<C>
impl<C> Freeze for SqlxTransactionCompanion<C>
impl<C> Send for SqlxTransactionCompanion<C>
impl<C> Sync for SqlxTransactionCompanion<C>
impl<C> Unpin for SqlxTransactionCompanion<C>
impl<C> UnsafeUnpin for SqlxTransactionCompanion<C>
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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