pub struct PgSqlClient { /* private fields */ }Expand description
PostgreSQL SqlClient backed by a sqlx connection pool.
Implementations§
Source§impl PgSqlClient
impl PgSqlClient
Sourcepub fn pool(&self) -> &PgPool
pub fn pool(&self) -> &PgPool
Borrow the underlying pool (for Apalis, obix, and other adapters).
Sourcepub fn pool_health(&self) -> Effect<BTreeMap<&'static str, u64>, SqlError>
pub fn pool_health(&self) -> Effect<BTreeMap<&'static str, u64>, SqlError>
Pool health check: runs SELECT 1 on a pooled connection, then reports the pool’s size
(open connections), idle connections and max_size. Fails (down) with the SqlError
when no connection can be acquired or the query fails.
Sourcepub fn layer<E>(config: PgPoolConfig) -> Layer<PgSqlEnv, E>
pub fn layer<E>(config: PgPoolConfig) -> Layer<PgSqlEnv, E>
The scoped PostgreSQL client Layer (Effect.ts Layer.scoped): building it opens a pool
from config and checks it with SELECT 1 (a failure fails the build with
E::from(err)); the build’s scope closing closes the pool. It provides the client as
SqlClientService and the pool as PgPool (PgSqlEnv).
Trait Implementations§
Source§impl Clone for PgSqlClient
impl Clone for PgSqlClient
Source§impl SqlClient for PgSqlClient
impl SqlClient for PgSqlClient
Source§fn query_stream(
&self,
sql: &str,
params: &[SqlValue],
) -> Stream<SqlRow, SqlError>
fn query_stream( &self, sql: &str, params: &[SqlValue], ) -> Stream<SqlRow, SqlError>
Streams the rows from a sqlx fetch on a pooled connection, buffering at most two batches
of 64 rows; dropping or interrupting the stream cancels the query on the server.
Source§fn connect(&self) -> Effect<(), SqlError>
fn connect(&self) -> Effect<(), SqlError>
Source§fn query(&self, sql: &str, params: &[SqlValue]) -> Effect<Vec<SqlRow>, SqlError>
fn query(&self, sql: &str, params: &[SqlValue]) -> Effect<Vec<SqlRow>, SqlError>
params bind to the placeholders in order
(¶ms![a, b], &[x.into()]).Source§fn execute(&self, sql: &str, params: &[SqlValue]) -> Effect<u64, SqlError>
fn execute(&self, sql: &str, params: &[SqlValue]) -> Effect<u64, SqlError>
Source§fn begin(&self) -> Effect<Arc<dyn SqlTransaction>, SqlError>
fn begin(&self) -> Effect<Arc<dyn SqlTransaction>, SqlError>
with_transaction, transaction or
transaction_layer, which always finish it.Source§fn close(&self) -> Effect<(), Never>
fn close(&self) -> Effect<(), Never>
sql_client_layer runs it when its
scope closes. The default does nothing.Source§fn begin_with(
&self,
options: TransactionOptions,
) -> Effect<Arc<dyn SqlTransaction>, SqlError>
fn begin_with( &self, options: TransactionOptions, ) -> Effect<Arc<dyn SqlTransaction>, SqlError>
options (isolation level, read-only, deferrable). The default
runs TransactionOptions::set_transaction_sql as the transaction’s first statement
(rolling back if it fails). Prefer
with_transaction_options /
transaction_with.Auto Trait Implementations§
impl !RefUnwindSafe for PgSqlClient
impl !UnwindSafe for PgSqlClient
impl Freeze for PgSqlClient
impl Send for PgSqlClient
impl Sync for PgSqlClient
impl Unpin for PgSqlClient
impl UnsafeUnpin for PgSqlClient
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> 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