pub struct PgPool { /* private fields */ }Expand description
A connection pool for PostgreSQL.
Implementations§
Source§impl PgPool
impl PgPool
Sourcepub async fn new(config: PgConfig) -> PgResult<Self>
pub async fn new(config: PgConfig) -> PgResult<Self>
Create a new connection pool from configuration.
Sourcepub async fn with_pool_config(
config: PgConfig,
pool_config: PoolConfig,
) -> PgResult<Self>
pub async fn with_pool_config( config: PgConfig, pool_config: PoolConfig, ) -> PgResult<Self>
Create a new connection pool with custom pool configuration.
Sourcepub async fn get(&self) -> PgResult<PgConnection>
pub async fn get(&self) -> PgResult<PgConnection>
Get a connection from the pool.
Sourcepub fn status(&self) -> PoolStatus
pub fn status(&self) -> PoolStatus
Get the current pool status.
Sourcepub async fn is_healthy(&self) -> bool
pub async fn is_healthy(&self) -> bool
Check if the pool is healthy by attempting to get a connection.
Sourcepub fn builder() -> PgPoolBuilder
pub fn builder() -> PgPoolBuilder
Create a builder for configuring the pool.
Sourcepub async fn warmup(&self, count: usize) -> PgResult<()>
pub async fn warmup(&self, count: usize) -> PgResult<()>
Warm up the connection pool by pre-establishing connections.
This eliminates the latency of establishing connections on the first queries.
The count parameter specifies how many connections to pre-establish.
§Example
ⓘ
let pool = PgPool::builder()
.url("postgresql://localhost/db")
.max_connections(10)
.build()
.await?;
// Pre-establish 5 connections
pool.warmup(5).await?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for PgPool
impl !RefUnwindSafe for PgPool
impl Send for PgPool
impl Sync for PgPool
impl Unpin for PgPool
impl !UnwindSafe for PgPool
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