Skip to content

Commit

Permalink
Apply updates for improved interop with SQLKit (#259)
Browse files Browse the repository at this point in the history
* Require Swift 5.8, update logo

* Code style cleanups

* Provide new SQLDatabase APIs from SQLKit's overhaul branch.

* Fix error handling in tests, remove redundant test

* Update CI

* Simplify readme
  • Loading branch information
gwynne committed Mar 25, 2024
1 parent 475bf6f commit f6c1bff
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 231 deletions.
33 changes: 0 additions & 33 deletions .github/contributing.md

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: ${{ false && !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container:
image: swift:5.9-jammy
image: swift:5.10-jammy
permissions: { actions: write, contents: read, security-events: write }
timeout-minutes: 60
steps:
Expand Down Expand Up @@ -111,10 +111,9 @@ jobs:
- postgres:14
- postgres:12
swift-image:
- swift:5.7-jammy
- swift:5.8-jammy
- swift:5.9-jammy
- swiftlang/swift:nightly-5.10-jammy
- swift:5.10-jammy
- swiftlang/swift:nightly-main-jammy
include:
- postgres-image: postgres:16
Expand Down Expand Up @@ -143,7 +142,7 @@ jobs:
linux-integration:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.9-jammy
container: swift:5.10-jammy
services:
psql-a:
image: postgres:16
Expand Down Expand Up @@ -194,11 +193,12 @@ jobs:
xcode-version: ${{ matrix.xcode-version }}
- name: Install Postgres, setup DB and auth, and wait for server start
run: |
brew upgrade || true
export PATH="$(brew --prefix)/opt/postgresql@14/bin:$PATH" PGDATA=/tmp/vapor-postgres-test
(brew unlink postgresql || true) && brew install "postgresql@15" && brew link --force "postgresql@15"
(brew unlink postgresql@14 || true) && brew install "postgresql@15" && brew link --force "postgresql@15"
initdb --locale=C --auth-host "scram-sha-256" -U "${POSTGRES_USER}" --pwfile=<(echo "${POSTGRES_PASSWORD}")
pg_ctl start --wait
timeout-minutes: 2
timeout-minutes: 15
- name: Checkout code
uses: actions/checkout@v4
- name: Run local tests
Expand Down
45 changes: 31 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -13,21 +13,38 @@ let package = Package(
.library(name: "PostgresKit", targets: ["PostgresKit"]),
],
dependencies: [
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.14.2"),
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.20.2"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.14.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0")
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0")
],
targets: [
.target(name: "PostgresKit", dependencies: [
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "PostgresNIO", package: "postgres-nio"),
.product(name: "SQLKit", package: "sql-kit"),
.product(name: "Atomics", package: "swift-atomics")
]),
.testTarget(name: "PostgresKitTests", dependencies: [
.target(name: "PostgresKit"),
.product(name: "SQLKitBenchmark", package: "sql-kit"),
]),
.target(
name: "PostgresKit",
dependencies: [
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "PostgresNIO", package: "postgres-nio"),
.product(name: "SQLKit", package: "sql-kit"),
.product(name: "Atomics", package: "swift-atomics"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "PostgresKitTests",
dependencies: [
.target(name: "PostgresKit"),
.product(name: "SQLKitBenchmark", package: "sql-kit"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
49 changes: 0 additions & 49 deletions Package@swift-5.9.swift

This file was deleted.

13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,19 @@
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/postgres-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/postgres-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/postgres-kit"><img src="https://img.shields.io/codecov/c/github/vapor/postgres-kit?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
</p>

<br>

🐘 Non-blocking, event-driven Swift client for PostgreSQL.

### Major Releases

The table below shows a list of PostgresKit major releases alongside their compatible NIO and Swift versions.

|Version|NIO|Swift|SPM|
|-|-|-|-|
|2.0|2.0|5.2+|`from: "2.0.0"`|
|1.0|1.0|4.0+|`from: "1.0.0"`|
### Usage

Use the SPM string to easily include the dependendency in your `Package.swift` file.

```swift
.package(url: "https://github.com/vapor/postgres-kit.git", from: ...)
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0")
```

### Supported Platforms
Expand Down
9 changes: 6 additions & 3 deletions Sources/PostgresKit/ConnectionPool+Postgres.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ extension EventLoopConnectionPool where Source == PostgresConnectionSource {
}
}


private struct _EventLoopGroupConnectionPoolPostgresDatabase: PostgresDatabase {
let pool: EventLoopGroupConnectionPool<PostgresConnectionSource>
let logger: Logger

var eventLoop: any EventLoop { self.pool.eventLoopGroup.any() }
var eventLoop: any EventLoop {
self.pool.eventLoopGroup.any()
}

func send(_ request: any PostgresRequest, logger: Logger) -> EventLoopFuture<Void> {
self.pool.withConnection(logger: logger) { $0.send(request, logger: logger) }
Expand All @@ -35,7 +36,9 @@ private struct _EventLoopConnectionPoolPostgresDatabase: PostgresDatabase {
let pool: EventLoopConnectionPool<PostgresConnectionSource>
let logger: Logger

var eventLoop: any EventLoop { self.pool.eventLoop }
var eventLoop: any EventLoop {
self.pool.eventLoop
}

func send(_ request: any PostgresRequest, logger: Logger) -> EventLoopFuture<Void> {
self.pool.withConnection(logger: logger) { $0.send(request, logger: logger) }
Expand Down
17 changes: 8 additions & 9 deletions Sources/PostgresKit/Docs.docc/images/vapor-postgreskit-logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions Sources/PostgresKit/Exports.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#if swift(>=5.8)

@_documentation(visibility: internal) @_exported import AsyncKit
@_documentation(visibility: internal) @_exported import PostgresNIO
@_documentation(visibility: internal) @_exported import SQLKit
@_documentation(visibility: internal) @_exported import struct Foundation.URL

#else

@_exported import AsyncKit
@_exported import PostgresNIO
@_exported import SQLKit
@_exported import struct Foundation.URL

#endif
2 changes: 1 addition & 1 deletion Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
}
}

extension PostgresConnection: ConnectionPoolItem { }
extension PostgresConnection: ConnectionPoolItem {}

0 comments on commit f6c1bff

Please sign in to comment.