diff --git a/test_runner/pg_clients/swift/PostgresNIOExample/.dockerignore b/test_runner/pg_clients/swift/PostgresNIOExample/.dockerignore new file mode 100644 index 0000000000..30bcfa4ed5 --- /dev/null +++ b/test_runner/pg_clients/swift/PostgresNIOExample/.dockerignore @@ -0,0 +1 @@ +.build/ diff --git a/test_runner/pg_clients/swift/PostgresNIOExample/.gitignore b/test_runner/pg_clients/swift/PostgresNIOExample/.gitignore new file mode 100644 index 0000000000..30bcfa4ed5 --- /dev/null +++ b/test_runner/pg_clients/swift/PostgresNIOExample/.gitignore @@ -0,0 +1 @@ +.build/ diff --git a/test_runner/pg_clients/swift/PostgresNIOExample/Dockerfile b/test_runner/pg_clients/swift/PostgresNIOExample/Dockerfile new file mode 100644 index 0000000000..629422d220 --- /dev/null +++ b/test_runner/pg_clients/swift/PostgresNIOExample/Dockerfile @@ -0,0 +1,10 @@ +FROM swift:5.7 AS build +WORKDIR /source + +COPY . . +RUN swift build --configuration release + +FROM swift:5.7 +WORKDIR /app +COPY --from=build /source/.build/release . +CMD ["/app/PostgresNIOExample"] diff --git a/test_runner/pg_clients/swift/PostgresNIOExample/Package.resolved b/test_runner/pg_clients/swift/PostgresNIOExample/Package.resolved new file mode 100644 index 0000000000..8246567b24 --- /dev/null +++ b/test_runner/pg_clients/swift/PostgresNIOExample/Package.resolved @@ -0,0 +1,86 @@ +{ + "pins" : [ + { + "identity" : "postgres-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/postgres-nio.git", + "state" : { + "revision" : "7daf026e145de2c07d6e37f4171b1acb4b5f22b1", + "version" : "1.12.1" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", + "version" : "1.0.4" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "75ec60b8b4cc0f085c3ac414f3dca5625fa3588e", + "version" : "2.2.4" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", + "version" : "1.5.2" + } + }, + { + "identity" : "swift-metrics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-metrics.git", + "state" : { + "revision" : "9b39d811a83cf18b79d7d5513b06f8b290198b10", + "version" : "2.3.3" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "45167b8006448c79dda4b7bd604e07a034c15c49", + "version" : "2.48.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3", + "version" : "2.23.0" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c", + "version" : "1.15.0" + } + } + ], + "version" : 2 +} diff --git a/test_runner/pg_clients/swift/PostgresNIOExample/Package.swift b/test_runner/pg_clients/swift/PostgresNIOExample/Package.swift new file mode 100644 index 0000000000..c64013b9ee --- /dev/null +++ b/test_runner/pg_clients/swift/PostgresNIOExample/Package.swift @@ -0,0 +1,17 @@ +// swift-tools-version:5.7 +import PackageDescription + +let package = Package( + name: "PostgresNIOExample", + dependencies: [ + .package(url: "https://github.com/vapor/postgres-nio.git", from: "1.8.0") + ], + targets: [ + .executableTarget( + name: "PostgresNIOExample", + dependencies: [ + .product(name: "PostgresNIO", package: "postgres-nio"), + ] + ) + ] +) diff --git a/test_runner/pg_clients/swift/PostgresNIOExample/Sources/PostgresNIOExample/main.swift b/test_runner/pg_clients/swift/PostgresNIOExample/Sources/PostgresNIOExample/main.swift new file mode 100644 index 0000000000..092a0b31f3 --- /dev/null +++ b/test_runner/pg_clients/swift/PostgresNIOExample/Sources/PostgresNIOExample/main.swift @@ -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 diff --git a/test_runner/pg_clients/test_pg_clients.py b/test_runner/pg_clients/test_pg_clients.py index 8018f1d004..5a8da56680 100644 --- a/test_runner/pg_clients/test_pg_clients.py +++ b/test_runner/pg_clients/test_pg_clients.py @@ -19,6 +19,7 @@ from fixtures.utils import subprocess_capture "swift/PostgresClientKitExample", # See https://github.com/neondatabase/neon/pull/2008#discussion_r911896592 marks=pytest.mark.xfail(reason="Neither SNI nor parameters is supported"), ), + "swift/PostgresNIOExample", "typescript/postgresql-client", ], )