A Swift connection pool built on PostgresNIO and PostgresKit. Manages a configurable set of reusable PostgreSQL connections with health checks, idle connection culling, automatic reconnection, and runtime diagnostics.
One product:
PostgresConnectionPool— library target:PostgresConnectionPoolactor,PoolConfiguration,PostgresConnectionWrapper,PoolInfo, and related types.
Key source areas:
PostgresConnectionPool.swift— Mainactor PostgresConnectionPool: init,connection(batchId:_:),shutdown(),abortBatch(_:),closeIdleConnections(),poolInfo(batchId:). Manages connection lifecycle (open, health check, release, close), idle connection culling, and continuation-based connection queue.PoolConfiguration.swift—PoolConfigurationstruct: connection parameters, pool size, timeouts, callbacks (onOpenConnection,onReturnConnection,onCloseConnection).PoolConnection.swift— InternalPoolConnectionclass: connection identity (atomic ID), usage counter, state machine (connecting/available/active/closed), query tracking.PoolConnectionState.swift—PoolConnectionStateenum:.active(Date),.available,.closed,.connecting.PoolContinuation.swift— Internal continuation wrapper for pending connection requests.PoolError.swift— Error enum:.cancelled,.connectionFailed,.poolDestroyed(PSQLError?),.postgresError(PSQLError),.queryCancelled,.unknown.PoolInfo.swift— Diagnostics:PoolInfoandPoolInfo.ConnectionInfostructs with connection counts, usage, queries, runtimes.PostgresConnectionWrapper.swift— Public connection handle: forwardsquery(),sql(),addListener(),listen(on:consume:)to the underlyingPostgresConnectionwhile tracking query text for runtime diagnostics.Extensions/— Helpers:EmptyTestable(isNotEmpty),FloatingPoint.rounded(toPlaces:),Double.atLeast(_:),Int.atLeast(_:),String.matches()/replacingPattern(),Task.after(seconds:priority:operation:),PSQLError.pgPoolDescription/pgPoolDebugDescription.
Dependencies:
- PostgresNIO — async PostgreSQL client,
PostgresConnection,PSQLError - PostgresKit —
SQLDatabaseintegration viaconnection.sql() - swift-atomics —
ManagedAtomic<Int>for connection IDs and usage counters - swift-collections —
Dequefor connection and continuation queues
swift build # build library
swift test # run all tests (Swift Testing)A running PostgreSQL container is required for integration tests. Use the provided docker-compose.yml:
docker compose up -d
swift testFollow the same conventions as mvt-tools (4-space indentation, no tabs, DocC documentation,
Swift 6 concurrency, Sendable conformance on all model types, actor for mutable state).
All public API must have DocC documentation.