mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-18 05:30:37 +00:00
Add a test for the PostgresNIO Swift client library.
It supports SNI. See discussion at https://community.neon.tech/t/postgresnio-swift-sni-support/419/4
This commit is contained in:
committed by
Heikki Linnakangas
parent
ec3a3aed37
commit
121d535068
@@ -0,0 +1,49 @@
|
||||
import Foundation
|
||||
|
||||
import PostgresNIO
|
||||
import NIOPosix
|
||||
import Logging
|
||||
|
||||
await Task {
|
||||
do {
|
||||
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||
let logger = Logger(label: "postgres-logger")
|
||||
|
||||
let env = ProcessInfo.processInfo.environment
|
||||
|
||||
let sslContext = try! NIOSSLContext(configuration: .makeClientConfiguration())
|
||||
|
||||
let config = PostgresConnection.Configuration(
|
||||
connection: .init(
|
||||
host: env["NEON_HOST"] ?? "",
|
||||
port: 5432
|
||||
),
|
||||
authentication: .init(
|
||||
username: env["NEON_USER"] ?? "",
|
||||
database: env["NEON_DATABASE"] ?? "",
|
||||
password: env["NEON_PASSWORD"] ?? ""
|
||||
),
|
||||
tls: .require(sslContext)
|
||||
)
|
||||
|
||||
let connection = try await PostgresConnection.connect(
|
||||
on: eventLoopGroup.next(),
|
||||
configuration: config,
|
||||
id: 1,
|
||||
logger: logger
|
||||
)
|
||||
|
||||
let rows = try await connection.query("SELECT 1 as col", logger: logger)
|
||||
for try await (n) in rows.decode((Int).self, context: .default) {
|
||||
print(n)
|
||||
}
|
||||
|
||||
// Close your connection once done
|
||||
try await connection.close()
|
||||
|
||||
// Shutdown the EventLoopGroup, once all connections are closed.
|
||||
try eventLoopGroup.syncShutdownGracefully()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}.value
|
||||
Reference in New Issue
Block a user