Expand description
Connection pooling support. Async connection pool for Hyper database.
This module provides connection pooling via deadpool for efficient
connection reuse in async applications.
§Example
use hyperdb_api::pool::{create_pool, PoolConfig};
use hyperdb_api::CreateMode;
#[tokio::main]
async fn main() -> hyperdb_api::Result<()> {
// Create a pool configuration
let config = PoolConfig::new("localhost:7483", "example.hyper")
.create_mode(CreateMode::CreateIfNotExists)
.max_size(16);
// Build the pool
let pool = create_pool(config)?;
// Get a connection from the pool
let conn = pool.get().await.map_err(|e| hyperdb_api::Error::new(e.to_string()))?;
// Use the connection
conn.execute_command("SELECT 1").await?;
// Connection is returned to pool when dropped
Ok(())
}§Lifecycle hooks
PoolConfig supports two async lifecycle hooks for users who need to
customize per-connection or per-checkout behavior:
after_connectruns once on every newly-opened connection (useful forSET search_path, prepared-statement warmup, etc.)before_acquireruns every time a connection is checked out (useful for session reset, telemetry, custom health checks)
health_check(bool) toggles the default per-checkout SELECT 1 probe —
disable it on hot paths where the roundtrip cost outweighs the value of
catching a half-dead connection at acquire time.
use hyperdb_api::pool::{create_pool, PoolConfig};
use hyperdb_api::CreateMode;
let config = PoolConfig::new("localhost:7483", "example.hyper")
.create_mode(CreateMode::CreateIfNotExists)
.max_size(16)
.health_check(false) // skip per-checkout SELECT 1
.after_connect(|conn| Box::pin(async move {
conn.execute_command("SET search_path TO public").await?;
Ok(())
}));
let _pool = create_pool(config)?;Structs§
- Connection
Manager - Connection pool manager for
AsyncConnection. - Pool
Config - Configuration for the connection pool.
Functions§
- create_
pool - Creates a new connection pool from configuration.
Type Aliases§
- After
Connect Hook - A hook that runs once on every newly-opened connection (after authentication and any database-creation handshake). Use it to set session variables, install statement caches, warm prepared statements, etc.
- Before
Acquire Hook - A hook that runs every time a connection is checked out of the pool, before it is handed to the caller. Use it for per-acquire health checks, session resets, or telemetry.
- Hook
Future - Future returned by pool lifecycle hooks.
- Pool
- A pool of async connections to a Hyper database.
- Pooled
Connection - A pooled connection wrapper.