Skip to content

Commit

Permalink
Adopt Async Shutdown (#221)
Browse files Browse the repository at this point in the history
* Drop support for Swift 5.8

* Update dependencies

* Adopt new APIs

* Fix some warnings in Swift 6

* Update CI
  • Loading branch information
0xTim authored Oct 6, 2024
1 parent e2988a8 commit fd57101
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 59 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ jobs:
- postgres-image-a: 'postgres:13'
postgres-image-b: 'postgres:14'
postgres-auth: 'trust'
swift-image: 'swift:5.8-focal'
swift-image: 'swift:5.9-focal'
- postgres-image-a: 'postgres:15'
postgres-image-b: 'postgres:16'
postgres-auth: 'md5'
swift-image: 'swift:5.10-jammy'
- postgres-image-a: 'postgres:15'
postgres-image-b: 'postgres:16'
postgres-auth: 'scram-sha-256'
swift-image: 'swiftlang/swift:nightly-6.0-jammy'
swift-image: 'swift:6.0-jammy'
container: ${{ matrix.swift-image }}
runs-on: ubuntu-latest
services:
Expand Down Expand Up @@ -89,8 +89,6 @@ jobs:
fail-fast: false
matrix:
include:
- macos-version: macos-13
xcode-version: '~14.3'
- macos-version: macos-14
xcode-version: latest
runs-on: ${{ matrix.macos-version }}
Expand Down
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.9
import PackageDescription

let package = Package(
Expand All @@ -13,8 +13,8 @@ let package = Package(
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
],
dependencies: [
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.4"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.20.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.49.0"),
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.13.4"),
],
targets: [
Expand All @@ -40,6 +40,9 @@ let package = Package(
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
48 changes: 0 additions & 48 deletions [email protected]

This file was deleted.

4 changes: 4 additions & 0 deletions Sources/FluentPostgresDriver/FluentPostgresDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ struct _FluentPostgresDriver<E: PostgresJSONEncoder, D: PostgresJSONDecoder>: Da
func shutdown() {
try? self.pool.syncShutdownGracefully()
}

func shutdownAsync() async {
try? await self.pool.shutdownAsync()
}
}
14 changes: 12 additions & 2 deletions Sources/FluentPostgresDriver/PostgresError+Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ fileprivate extension PostgresError.Code {
}
}

extension PostgresError: DatabaseError {
// Used for DatabaseError conformance
extension PostgresError {
public var isSyntaxError: Bool { self.code.isSyntaxError }
public var isConnectionClosed: Bool {
switch self {
Expand All @@ -82,7 +83,8 @@ extension PostgresError: DatabaseError {
public var isConstraintFailure: Bool { self.code.isConstraintFailure }
}

extension PSQLError: DatabaseError {
// Used for DatabaseError conformance
extension PSQLError {
public var isSyntaxError: Bool {
switch self.code {
case .server: return self.serverInfo?[.sqlState].map { PostgresError.Code(raw: $0).isSyntaxError } ?? false
Expand All @@ -104,3 +106,11 @@ extension PSQLError: DatabaseError {
}
}
}

#if compiler(<6)
extension PostgresError: DatabaseError { }
extension PSQLError: DatabaseError { }
#else
extension PostgresError: @retroactive DatabaseError { }
extension PSQLError: @retroactive DatabaseError { }
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ final class FluentPostgresDriverTests: XCTestCase {
}

override func tearDown() async throws {
self.dbs.shutdown()
await self.dbs.shutdownAsync()
try await super.tearDown()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class FluentPostgresTransactionControlTests: XCTestCase {

override func tearDown() async throws {
try await CreateTodo().revert(on: self.db)
self.dbs.shutdown()
await self.dbs.shutdownAsync()
try await super.tearDown()
}

Expand Down

0 comments on commit fd57101

Please sign in to comment.