pub struct SqlxRuntime { /* private fields */ }Implementations§
Source§impl SqlxRuntime
impl SqlxRuntime
pub fn new(pool: PgPool) -> Self
pub fn pool(&self) -> &PgPool
Sourcepub fn with_audit_sink(self, sink: Arc<dyn AuditSink>) -> Self
pub fn with_audit_sink(self, sink: Arc<dyn AuditSink>) -> Self
Install a custom AuditSink that every @@audit mutation on
this runtime fans out to, in addition to the in-database
cratestack_audit table row enqueue_audit_event always
writes. Composable via cratestack_core::MulticastAuditSink
for more than one downstream (Kafka, Redis pubsub, a webhook —
this crate ships none of them; see AuditSink’s doc comment).
Source§impl SqlxRuntime
impl SqlxRuntime
Sourcepub async fn transaction<F, T>(&self, body: F) -> Result<T, CratestackError>
pub async fn transaction<F, T>(&self, body: F) -> Result<T, CratestackError>
Run body inside one Postgres transaction: commit if it returns
Ok, roll back if it returns Err. body receives an opaque Tx
it can pass straight through to any write builder’s run_in_tx —
see the module doc comment for why no sqlx type ever needs to be
named to do that.
On the Err path this issues an explicit tx.rollback().await
rather than relying on sqlx::Transaction’s Drop impl. That
matters: sqlx-core’s Drop for Transaction only queues a
rollback for the next time the underlying connection is used (see
sqlx-core::transaction::Transaction’s Drop impl) — it does not
synchronously roll back. A caller asserting “neither write is
visible” immediately after an Err return needs that to have
already happened, not to be pending on some future unrelated query.
Does not retry — see the module doc comment for why that’s left to
crate::run_in_isolated_tx instead, and how the two compose.
Does not dispatch to an installed AuditSink or drain the
@@emit outbox on its own — see the module doc comment’s
“Composing through here does not close the AuditSink/outbox gap”
section (cratestack#534) for why that can’t be made automatic here.
Trait Implementations§
Source§impl Clone for SqlxRuntime
impl Clone for SqlxRuntime
Source§fn clone(&self) -> SqlxRuntime
fn clone(&self) -> SqlxRuntime
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SqlxRuntime
impl !UnwindSafe for SqlxRuntime
impl Freeze for SqlxRuntime
impl Send for SqlxRuntime
impl Sync for SqlxRuntime
impl Unpin for SqlxRuntime
impl UnsafeUnpin for SqlxRuntime
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
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> ⓘ
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