Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sendable cleanup #271

Merged
merged 7 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 36 additions & 77 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
api-breakage:
if: ${{ github.event_name == 'pull_request' && !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:jammy
container: swift:noble
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -36,86 +36,25 @@ jobs:
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
swift package diagnose-api-breaking-changes origin/main

dependency-graph:
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
container: swift:jammy
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Fix Git configuration
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
apt-get update && apt-get install -y curl
- name: Submit dependency graph
uses: vapor-community/[email protected]

code-coverage:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:jammy
services:
psql-a:
image: postgres:16
env:
POSTGRES_USER: test_username
POSTGRES_DB: test_database
POSTGRES_PASSWORD: test_password
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests for coverage data
run: swift test --enable-code-coverage
- name: Upload coverage data
uses: vapor/[email protected]
with:
codecov_token: ${{ secrets.CODECOV_TOKEN }}

# gh-codeql:
# if: ${{ !(github.event.pull_request.draft || false) }}
# runs-on: ubuntu-latest
# container:
# image: swift:5.10-jammy
# permissions: { actions: write, contents: read, security-events: write }
# timeout-minutes: 60
# steps:
# - name: Check out code
# uses: actions/checkout@v4
# - name: Mark repo safe in non-fake global config
# run: |
# git config --global --add safe.directory "${GITHUB_WORKSPACE}"
# - name: Initialize CodeQL
# uses: github/codeql-action/init@v3
# with: { languages: swift }
# - name: Perform build
# run: swift build
# - name: Run CodeQL analyze
# uses: github/codeql-action/analyze@v3

linux-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
postgres-image:
- postgres:16
- postgres:14
- postgres:12
- postgres:17
- postgres:15
- postgres:13
swift-image:
- swift:5.8-jammy
- swift:5.9-jammy
- swift:5.10-jammy
- swiftlang/swift:nightly-main-jammy
- swift:5.10-noble
- swift:6.0-noble
include:
- postgres-image: postgres:16
- postgres-image: postgres:17
postgres-auth: scram-sha-256
- postgres-image: postgres:14
- postgres-image: postgres:15
postgres-auth: md5
- postgres-image: postgres:12
- postgres-image: postgres:13
postgres-auth: trust
runs-on: ubuntu-latest
container: ${{ matrix.swift-image }}
Expand All @@ -132,15 +71,19 @@ jobs:
- name: Check out package
uses: actions/checkout@v4
- name: Run local tests
run: swift test --sanitize=thread
run: swift test --sanitize=thread --enable-code-coverage
- name: Upload coverage data
uses: vapor/[email protected]
with:
codecov_token: ${{ secrets.CODECOV_TOKEN || '' }}

linux-integration:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-jammy
container: swift:6.0-noble
services:
psql-a:
image: postgres:16
image: postgres:17
env:
POSTGRES_USER: test_username
POSTGRES_DB: test_database
Expand Down Expand Up @@ -173,10 +116,10 @@ jobs:
fail-fast: false
matrix:
include:
- macos-version: macos-13
xcode-version: '~14.3'
- macos-version: macos-14
xcode-version: latest
xcode-version: latest-stable
- macos-version: macos-15
xcode-version: latest-stable
runs-on: ${{ matrix.macos-version }}
env:
POSTGRES_HOSTNAME: 127.0.0.1
Expand All @@ -197,4 +140,20 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Run local tests
run: swift test --sanitize=thread
run: swift test --sanitize=thread --enable-code-coverage
- name: Upload coverage data
uses: vapor/[email protected]
with:
codecov_token: ${{ secrets.CODECOV_TOKEN || '' }}

musl:
runs-on: ubuntu-latest
container: swift:6.0-noble
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install SDK
run: swift sdk install https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum 67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd
- name: Build
run: swift build --swift-sdk x86_64-swift-linux-musl
5 changes: 4 additions & 1 deletion 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 Down Expand Up @@ -39,6 +39,9 @@ let package = Package(
)

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

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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/swift58up.svg" alt="Swift 5.8+"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+"></a>
</p>

<br>
Expand Down
8 changes: 4 additions & 4 deletions Sources/PostgresKit/ConnectionPool+Postgres.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NIOCore
import PostgresNIO
@preconcurrency import AsyncKit
import Logging
import NIOCore
import PostgresNIO

extension EventLoopGroupConnectionPool where Source == PostgresConnectionSource {
public func database(logger: Logger) -> any PostgresDatabase {
Expand Down Expand Up @@ -39,11 +39,11 @@ private struct _EventLoopConnectionPoolPostgresDatabase: PostgresDatabase {
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) }
}

func withConnection<T>(_ closure: @escaping (PostgresConnection) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
self.pool.withConnection(logger: self.logger, closure)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOSSL
import Foundation
import NIOCore
import NIOSSL

@available(*, deprecated, message: "Use `SQLPostgresConfiguration` instead.")
public struct PostgresConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import NIOSSL
import Atomics
import Logging
import PostgresNIO
import NIOCore
import NIOSSL
import PostgresNIO

extension PostgresConnectionSource {
@available(*, deprecated, message: "Use `sqlConfiguration` instead.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PostgresNIO
import Foundation
import PostgresNIO
import SQLKit

@available(*, deprecated, message: "Use `.sql(jsonEncoder:jsonDecoder:)` instead.")
Expand Down
3 changes: 3 additions & 0 deletions Sources/PostgresKit/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"psqlkit": "#336791",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-psqlkit) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-psqlkit)",
"documentation-intro-eyebrow": "white",
"documentation-intro-figure": "white",
"documentation-intro-title": "white",
"logo-base": { "dark": "#fff", "light": "#000" },
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
Expand Down
19 changes: 11 additions & 8 deletions Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import NIOSSL
import NIOConcurrencyHelpers
import AsyncKit
import Logging
import NIOConcurrencyHelpers
import NIOCore
import NIOSSL
import PostgresNIO
import SQLKit
import NIOCore

public struct PostgresConnectionSource: ConnectionPoolSource {
public let sqlConfiguration: SQLPostgresConfiguration

private static let idGenerator = NIOLockedValueBox<Int>(0)

public init(sqlConfiguration: SQLPostgresConfiguration) {
self.sqlConfiguration = sqlConfiguration
}
Expand All @@ -22,10 +22,13 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
let connectionFuture = PostgresConnection.connect(
on: eventLoop,
configuration: self.sqlConfiguration.coreConfiguration,
id: Self.idGenerator.withLockedValue { $0 += 1; return $0 },
id: Self.idGenerator.withLockedValue {
$0 += 1
return $0
},
logger: logger
)

if let searchPath = self.sqlConfiguration.searchPath {
return connectionFuture.flatMap { conn in
conn.sql(queryLogLevel: nil)
Expand All @@ -39,4 +42,4 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
}
}

extension PostgresConnection: ConnectionPoolItem {}
extension PostgresNIO.PostgresConnection: AsyncKit.ConnectionPoolItem {}
4 changes: 2 additions & 2 deletions Sources/PostgresKit/PostgresDataTranslation.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PostgresNIO
import Foundation
import PostgresNIO

/// Quick and dirty ``CodingKey``, borrowed from FluentKit. If ``CodingKeyRepresentable`` wasn't broken by design
/// (specifically, it can't be back-deployed before macOS 12.3 etc., even though it was introduced in Swift 5.6),
Expand All @@ -17,7 +17,7 @@ private extension PostgresCell {
}

/// Sidestep problems with URL coding behavior by making it conform directly to Postgres coding.
extension URL: PostgresNonThrowingEncodable, PostgresDecodable {
extension Foundation.URL: PostgresNIO.PostgresNonThrowingEncodable, PostgresNIO.PostgresDecodable {
public static var psqlType: PostgresDataType {
String.psqlType
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgresKit/PostgresDatabase+SQL.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PostgresNIO
import Logging
import PostgresNIO
import SQLKit

extension PostgresDatabase {
Expand Down Expand Up @@ -95,7 +95,7 @@ extension PostgresSQLDatabase: SQLDatabase, PostgresDatabase {
self.database.withConnection(closure)
}

func withSession<R>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R {
func withSession<R: Sendable>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R {
try await self.withConnection { c in
c.eventLoop.makeFutureWithTask {
try await closure(c.sql(
Expand Down
6 changes: 3 additions & 3 deletions Sources/PostgresKit/PostgresRow+SQL.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import PostgresNIO
import Foundation
import PostgresNIO
import SQLKit

extension PostgresRow {
@inlinable
public func sql() -> some SQLRow {
self.sql(decodingContext: .default)
}

public func sql(decodingContext: PostgresDecodingContext<some PostgresJSONDecoder>) -> some SQLRow {
_PostgresSQLRow(randomAccessView: self.makeRandomAccess(), decodingContext: decodingContext)
}
Expand Down Expand Up @@ -39,7 +39,7 @@ extension _PostgresSQLRow: SQLRow {
guard self.randomAccessView.contains(column) else {
throw _Error.missingColumn(column)
}

return try PostgresDataTranslation.decode(T.self, from: self.randomAccessView[column], in: self.decodingContext)
}
}
Loading
Loading