vapor/postgres-kit
vapor/postgres-kit has 225 GitHub stars and 72 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-09 22:18 UTC. Last push 2026-09-24.
🐘 Non-blocking, event-driven Swift client for PostgreSQL.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 업데이트 지연
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalPostgresKit is an SQLKit driver for PostgreSQL clients.
Overview
PostgresKit supports building and serializing Postgres-dialect SQL queries using SQLKit's API. PostgresKit uses PostgresNIO to connect and communicate with the database server asynchronously. AsyncKit is used to provide connection pooling.
Important: It is strongly recommended that users who leverage PostgresKit directly (e.g. absent the Fluent ORM layer) take advantage of PostgresNIO's PostgresClient API for connection management rather than relying upon the legacy AsyncKit API.
Usage
Reference this package in your Package.swift to include it in your project.
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0")
Supported Platforms
PostgresKit supports the following platforms:
- Ubuntu 20.04+
- macOS 10.15+
Configuration
Database connection options and credentials are specified using a SQLPostgresConfiguration struct.
import PostgresKit
let configuration = SQLPostgresConfiguration(
hostname: "localhost",
username: "vapor_username",
password: "vapor_password",
database: "vapor_database"
)
URL-based configuration is also supported.
guard let configuration = SQLPostgresConfiguration(url: "postgres://...") else {
...
}
To connect via unix-domain sockets, use SQLPostgresConfiguration/init(unixDomainSocketPath:username:password:database:) instead of SQLPostgresConfiguration/init(hostname:port:username:password:database:tls:).
let configuration = SQLPostgresConfiguration(
unixDomainSocketPath: "/path/to/socket",
username: "vapor_username",
password: "vapor_password",
database: "vapor_database"
)
Connection Pool (Modern PostgresNIO)
You don't need a SQLPostgresConfiguration to create a PostgresClient, an instance of PostgresNIO's modern connection pool. Instead, use PostgresClient's native configuration type:
let configuration = PostgresClient.Configuration(
host: "localhost",
username: "vapor_username",
password: "vapor_password",
database: "vapor_database",
tls: .prefer(.makeClientConfiguration())
)
let psqlClient = PostgresClient(configuration: configuration)
// Start a Task to run the client:
let clientTask = Task { await client.run() }
// Or, if you're using ServiceLifecycle, add the client to a ServiceGroup:
await serviceGroup.addServiceUnlessShutdown(client)
You can then lease a PostgresConnection from the client:
try await client.withConnection { conn in
print(conn) // PostgresConnection managed by PostgresClient's connection pool
}
[!NOTE]
PostgresClient.Configurationdoes not support URL-based configuration. If you want to handle URLs, you can create an instance ofSQLPostgresConfigurationand translate it into aPostgresClient.Configuration:extension PostgresClient.Configuration { init(from configuration: PostgresConnection.Configuration) { let tls: PostgresClient.Configuration.TLS = switch (configuration.tls.isEnforced, configuration.tls.isAllowed) { case (true, _): .require(configuration.tls.sslContext!.configuration) case (_, true): .prefer(configuration.tls.sslContext!.configuration) default: .disable } if let host = configuration.host, let port = configuration.port { self.init(host: host, port: port, username: configuration.username, password: configuration.password, database: configuration.database, tls: tls) } else if let socket = configuration.unixSocketPath { self.init(unixSocketPath: socket, username: configuration.username, password: configuration.password, database: configuration.database) } else { fatalError("Preconfigured channels not supported") } } } guard let sqlConfiguration = SQLPostgresConfiguration(url: "...") else { ... } let clientConfiguration = PostgresClient.Configuration(configuration: sqlConfiguration.coreConfiguration)
Connection Pool (Legacy AsyncKit)
[!WARNING] AsyncKit is deprecated; using it is strongly discouraged. You should not use this setup unless you are also working with FluentKit, which at the time of this writing is not compatible with
PostgresClient.
Once you have a SQLPostgresConfiguration, you can use it to create a connection source and pool.
let eventLoopGroup: EventLoopGroup = NIOSingletons.posixEventLoopGroup
let pools = EventLoopGroupConnectionPool(
source: PostgresConnectionSource(configuration: configuration),
on: eventLoopGroup
)
// When you're done:
try await pools.shutdownAsync()
First create a PostgresConnectionSource using the configuration struct. This type is responsible for creating new connections to your database server as needed.
Next, use the connection source to create an EventLoopGroupConnectionPool. You will also need to pass an EventLoopGroup. For more information on creating an EventLoopGroup, visit SwiftNIO's documentation. Make sure to shutdown the connection pool before it deinitializes.
EventLoopGroupConnectionPool is a collection of pools for each event loop. When using EventLoopGroupConnectionPool directly, random event loops will be chosen as needed.
pools.withConnection { conn in
print(conn) // PostgresConnection on randomly chosen event loop
}
To get a pool for a specific event loop, use pool(for:). This returns an EventLoopConnectionPool.
let eventLoop: EventLoop = ...
let pool = pools.pool(for: eventLoop)
pool.withConnection { conn in
print(conn) // PostgresConnection on eventLoop
}
PostgresDatabase
Both EventLoopGroupConnectionPool and EventLoopConnectionPool can be used to create instances of PostgresDatabase.
let postgres = pool.database(logger: ...) // PostgresDatabase
let rows = try await postgres.simpleQuery("SELECT version()")
Visit PostgresNIO's docs for more information on using PostgresDatabase.
SQLDatabase
A PostgresDatabase can be used to create an instance of SQLDatabase.
let sql = postgres.sql() // SQLDatabase
let planets = try await sql.select().column("*").from("planets").all()
Visit SQLKit's docs for more information on using SQLDatabase.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,486 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,790 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,332 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,455 스타