Expand description
Connection pooling for SQLModel Rust using asupersync.
sqlmodel-pool is the connection lifecycle layer. It provides a generic,
budget-aware pool that integrates with structured concurrency and can wrap any
Connection implementation.
§Role In The Architecture
- Shared connection management: reuse connections across tasks safely.
- Budget-aware acquisition: respects
Cxtimeouts and cancellation. - Health checks: validates connections before handing them out.
- Metrics: exposes stats for pool sizing and tuning.
§Features
- Generic over any
Connectiontype - RAII-based connection return (connections returned on drop)
- Timeout support via
Cxcontext - Connection health validation
- Idle and max lifetime tracking
- Pool statistics
§Example
ⓘ
use sqlmodel_pool::{Pool, PoolConfig};
// Create a pool
let config = PoolConfig::new(10)
.min_connections(2)
.acquire_timeout(5000);
let pool = Pool::new(config, || async {
// Factory function to create new connections
PgConnection::connect(&cx, &pg_config).await
});
// Acquire a connection
let conn = pool.acquire(&cx).await?;
// Use the connection (automatically returned to pool on drop)
conn.query(&cx, "SELECT 1", &[]).await?;Re-exports§
pub use replica::ReplicaPool;pub use replica::ReplicaStrategy;pub use sharding::ModuloShardChooser;pub use sharding::QueryHints;pub use sharding::ShardChooser;pub use sharding::ShardedPool;pub use sharding::ShardedPoolStats;
Modules§
- replica
- Read replica routing for connection pools.
- sharding
- Horizontal sharding support for SQLModel Rust.
Structs§
- Pool
- A connection pool for database connections.
- Pool
Config - Connection pool configuration.
- Pool
Stats - Pool statistics.
- Pooled
Connection - A connection borrowed from the pool.