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

Update required versions of dependencies #265

Merged
merged 1 commit into from
May 16, 2024
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
9 changes: 2 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ let package = Package(
.library(name: "PostgresKit", targets: ["PostgresKit"]),
],
dependencies: [
.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/postgres-nio.git", from: "1.21.1"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.3"),
.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(
Expand All @@ -25,7 +24,6 @@ let package = Package(
.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
),
Expand All @@ -43,7 +41,4 @@ let package = Package(
var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
3 changes: 0 additions & 3 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ let package = Package(
.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.19.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0")
],
targets: [
.target(
Expand All @@ -25,7 +24,6 @@ let package = Package(
.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
),
Expand All @@ -45,6 +43,5 @@ var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
6 changes: 3 additions & 3 deletions Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NIOSSL
import Atomics
import NIOConcurrencyHelpers
import AsyncKit
import Logging
import PostgresNIO
Expand All @@ -9,7 +9,7 @@ import NIOCore
public struct PostgresConnectionSource: ConnectionPoolSource {
public let sqlConfiguration: SQLPostgresConfiguration

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

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

Expand Down
17 changes: 5 additions & 12 deletions Sources/PostgresKit/PostgresDatabase+SQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,18 @@ extension PostgresDatabase {
decodingContext: PostgresDecodingContext<some PostgresJSONDecoder>,
queryLogLevel: Logger.Level? = .debug
) -> some SQLDatabase {
_PostgresSQLDatabase(database: self, encodingContext: encodingContext, decodingContext: decodingContext, queryLogLevel: queryLogLevel)
PostgresSQLDatabase(database: self, encodingContext: encodingContext, decodingContext: decodingContext, queryLogLevel: queryLogLevel)
}
}

private struct _PostgresSQLDatabase<PDatabase: PostgresDatabase, E: PostgresJSONEncoder, D: PostgresJSONDecoder> {
private struct PostgresSQLDatabase<PDatabase: PostgresDatabase, E: PostgresJSONEncoder, D: PostgresJSONDecoder> {
let database: PDatabase
let encodingContext: PostgresEncodingContext<E>
let decodingContext: PostgresDecodingContext<D>
let queryLogLevel: Logger.Level?

init(database: PDatabase, encodingContext: PostgresEncodingContext<E>, decodingContext: PostgresDecodingContext<D>, queryLogLevel: Logger.Level?) {
self.database = database
self.encodingContext = encodingContext
self.decodingContext = decodingContext
self.queryLogLevel = queryLogLevel
}
}

extension _PostgresSQLDatabase: SQLDatabase, PostgresDatabase {
extension PostgresSQLDatabase: SQLDatabase, PostgresDatabase {
var logger: Logger {
self.database.logger
}
Expand All @@ -51,7 +44,7 @@ extension _PostgresSQLDatabase: SQLDatabase, PostgresDatabase {
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> ()) -> EventLoopFuture<Void> {
let (sql, binds) = self.serialize(query)

if let queryLogLevel {
if let queryLogLevel = self.queryLogLevel {
self.logger.log(level: queryLogLevel, "\(sql) [\(binds)]")
}
return self.eventLoop.makeCompletedFuture {
Expand All @@ -75,7 +68,7 @@ extension _PostgresSQLDatabase: SQLDatabase, PostgresDatabase {
) async throws {
let (sql, binds) = self.serialize(query)

if let queryLogLevel {
if let queryLogLevel = self.queryLogLevel {
self.logger.log(level: queryLogLevel, "\(sql) [\(binds)]")
}

Expand Down
Loading