pub struct PgPool { /* private fields */ }Expand description
PostgreSQL connection pool.
§Example
ⓘ
let config = PoolConfig::new("localhost", 5432, "user", "db")
.password("secret")
.max_connections(20);
let pool = PgPool::connect(config).await?;
// Get a connection from the pool
let mut conn = pool.acquire().await?;
conn.simple_query("SELECT 1").await?;
// Connection automatically returned when droppedImplementations§
Source§impl PgPool
impl PgPool
Sourcepub async fn connect(config: PoolConfig) -> PgResult<Self>
pub async fn connect(config: PoolConfig) -> PgResult<Self>
Create a new connection pool.
Sourcepub async fn acquire(&self) -> PgResult<PooledConnection>
pub async fn acquire(&self) -> PgResult<PooledConnection>
Acquire a connection from the pool.
Waits if all connections are in use (up to acquire_timeout). Stale connections (idle > idle_timeout) are automatically discarded. Connection is automatically returned when dropped.
Sourcepub async fn idle_count(&self) -> usize
pub async fn idle_count(&self) -> usize
Get the current number of idle connections.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Get the number of connections currently in use.
Sourcepub fn max_connections(&self) -> usize
pub fn max_connections(&self) -> usize
Get the maximum number of connections.
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