https://github.com/outdooractive/postgresconnectionpool
A simple connection pool on top of PostgresNIO written in Swift.
https://github.com/outdooractive/postgresconnectionpool
pool postgres-kit postgres-nio postgresql swift
Last synced: 5 months ago
JSON representation
A simple connection pool on top of PostgresNIO written in Swift.
- Host: GitHub
- URL: https://github.com/outdooractive/postgresconnectionpool
- Owner: Outdooractive
- License: mit
- Created: 2022-08-25T14:55:01.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-21T12:15:35.000Z (over 1 year ago)
- Last Synced: 2025-04-10T23:35:27.879Z (about 1 year ago)
- Topics: pool, postgres-kit, postgres-nio, postgresql, swift
- Language: Swift
- Homepage:
- Size: 74.2 KB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# PostgresConnectionPool
A simple connection pool on top of [PostgresNIO](https://github.com/vapor/postgres-nio) and [PostgresKit](https://github.com/vapor/postgres-kit).
[](https://swiftpackageindex.com/Outdooractive/PostgresConnectionPool)
[](https://swiftpackageindex.com/Outdooractive/PostgresConnectionPool)
## Requirements
This package requires Swift 5.7 or higher (at least Xcode 13), and compiles on macOS (\>= macOS 10.15) and Linux.
## Installation with Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/Outdooractive/PostgresConnectionPool.git", from: "0.7.0"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "PostgresConnectionPool", package: "PostgresConnectionPool"),
]),
]
```
## Usage
Please see also the [API documentation](https://swiftpackageindex.com/Outdooractive/PostgresConnectionPool/main/documentation/postgresconnectionpool).
``` swift
import PostgresConnectionPool
import PostgresKit
import PostgresNIO
var logger = Logger(label: "TestApp")
logger.logLevel = .debug
let postgresConfiguration = PostgresConnection.Configuration(
host: "postgres",
port: 5432,
username: "testuser",
password: "testpassword",
database: "test",
tls: .disable)
let configuration = PoolConfiguration(
applicationName: "TestApp",
postgresConfiguration: postgresConfiguration,
connectTimeout: 10.0,
queryTimeout: 60.0,
poolSize: 5,
maxIdleConnections: 1)
let pool = PostgresConnectionPool(configuration: configuration, logger: logger)
// Fetch a connection from the pool and do something with it...
try await pool.connection { connection in
try await connection.query(PostgresQuery(stringLiteral: "SELECT 1"), logger: logger)
}
// With PostgresKit
func fetchObjects(_ sql: SQLQueryString) async throws -> [T] {
try await pool.connection({ connection in
return try await connection.sql().raw(sql).all(decoding: T.self)
})
}
// Open connections, current SQL queries, etc.
await print(pool.info())
// Always call `shutdown()` before releasing a pool
await pool.shutdown()
```
## Contributing
Please create an issue or open a pull request with a fix or enhancement.
## License
MIT
## Author
Thomas Rasch, Outdooractive