#database-connection-pool #sql #sqlmodel #connection-pool

sqlmodel-pool

Connection pooling for SQLModel Rust using asupersync

4 releases

Uses new Rust 2024

0.2.2 Apr 23, 2026
0.2.1 Mar 22, 2026
0.2.0 Feb 15, 2026
0.1.1 Feb 5, 2026

#5 in #database-connection-pool


Used in sqlmodel

MIT license

500KB
11K SLoC

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 Cx timeouts and cancellation.
  • Health checks: validates connections before handing them out.
  • Metrics: exposes stats for pool sizing and tuning.

Features

  • Generic over any Connection type
  • RAII-based connection return (connections returned on drop)
  • Timeout support via Cx context
  • 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?;

sqlmodel-pool

Structured-concurrency-aware connection pooling.

Role in the SQLModel Rust System

  • Budget-aware acquisition via Cx timeouts and cancellation.
  • Health checks and lifecycle management for connections.
  • Works with any sqlmodel-core::Connection implementation.

Usage

Most users should depend on sqlmodel and import from sqlmodel::prelude::*. Use this crate directly if you are extending internals or building tooling around the core APIs.

Dependencies

~54MB
~1M SLoC