qail_pg/driver/pool/mod.rs
1//! PostgreSQL Connection Pool
2//!
3//! Provides connection pooling with prepared-statement caching, RLS pipelining,
4//! churn protection, and hot-statement cross-connection sharing.
5
6mod churn;
7mod config;
8mod connection;
9mod fetch;
10mod gss;
11mod lifecycle;
12#[cfg(test)]
13mod tests;
14
15use crate::driver::PgResult;
16use std::future::Future;
17use std::pin::Pin;
18
19/// Boxed async return type for scoped pool helpers (`with_rls`, `with_tenant`, etc.).
20pub type ScopedPoolFuture<'a, T> = Pin<Box<dyn Future<Output = PgResult<T>> + Send + 'a>>;
21
22/// Helper to box async closures for scoped pool helpers.
23///
24/// This avoids writing `Box::pin(...)` directly at every callsite.
25///
26/// # Example
27/// ```ignore
28/// use qail_pg::scope;
29///
30/// let users = pool
31/// .with_tenant(tenant_id, |conn| scope(async move {
32/// conn.fetch_all_uncached(&cmd).await
33/// }))
34/// .await?;
35/// ```
36#[inline]
37pub fn scope<'a, T, Fut>(fut: Fut) -> ScopedPoolFuture<'a, T>
38where
39 Fut: Future<Output = PgResult<T>> + Send + 'a,
40{
41 Box::pin(fut)
42}
43
44// ── Public API ──────────────────────────────────────────────────────
45pub use churn::PoolStats;
46pub use config::PoolConfig;
47pub use connection::PooledConnection;
48pub use lifecycle::{PgPool, spawn_pool_maintenance};
49
50// ── Crate-internal ──────────────────────────────────────────────────
51pub(crate) use config::apply_url_query_params;