pub struct Pool<DB>(/* private fields */);Expand description
The pool a handler queries through: writes through it commit on their own, whatever the delivery’s outcome.
It reads PoolContext, which every delivery of an InboxQueue subscription lends, or
TxContext after Ctx<keys::Tx<..>>. On the app’s runtime it yields the service’s pool.
On a dedicated thread it yields the thread’s own pool, built from the service pool’s options
on the first read there. Its connections open on the thread and close with it, so none
outlives the thread’s runtime in the service’s pool. It opens one connection at most, or the
number InboxThreads::connections sets. A read costs one
thread-local access and one clone of a pool handle. A pool’s type names its database, and so does the key: keys::Pool<Postgres>.
§Examples
use ruststream_sqlx::prelude::*;
use sqlx::Postgres;
#[subscriber(InboxQueue::<Job>::new("visits"))]
async fn count(visit: &Visit, Ctx(pool): Ctx<keys::Pool<Postgres>>) -> HandlerOutcome {
let counted = sqlx::query("UPDATE pages SET visits = visits + 1 WHERE path = $1")
.bind(&visit.page)
.execute(&pool)
.await;
if counted.is_ok() { HandlerOutcome::ack() } else { HandlerOutcome::retry() }
}Trait Implementations§
Source§impl<DB: QueueDatabase> ContextField for Pool<DB>
impl<DB: QueueDatabase> ContextField for Pool<DB>
Source§type Context = PoolContext<DB>
type Context = PoolContext<DB>
The per-delivery context type this key reads from.
Source§fn read(self, src: &PoolContext<DB>) -> DbPool<DB>
fn read(self, src: &PoolContext<DB>) -> DbPool<DB>
Reads this key’s field out of
src. Named apart from Field::get so a key
implementing both traits stays unambiguous to call.impl<DB> Copy for Pool<DB>
Auto Trait Implementations§
impl<DB> Freeze for Pool<DB>
impl<DB> RefUnwindSafe for Pool<DB>
impl<DB> Send for Pool<DB>
impl<DB> Sync for Pool<DB>
impl<DB> Unpin for Pool<DB>
impl<DB> UnsafeUnpin for Pool<DB>
impl<DB> UnwindSafe for Pool<DB>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K> CtxKey for Kwhere
K: ContextField,
impl<K> CtxKey for Kwhere
K: ContextField,
Source§type Value = <K as ContextField>::Value
type Value = <K as ContextField>::Value
The owned value the extractor binds.
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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