Skip to content

Some minor cleanup #224

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

Merged
merged 4 commits into from
Apr 13, 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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*.swift]
indent_style = space
indent_size = 4
tab_width = 4
insert_final_newline = true
trim_trailing_whitespace = true

26 changes: 13 additions & 13 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 @@ -42,18 +42,18 @@ jobs:
fail-fast: false
matrix:
include:
- postgres-image-a: 'postgres:13'
postgres-image-b: 'postgres:14'
- postgres-image-a: 'postgres:12'
postgres-image-b: 'postgres:13'
postgres-auth: 'trust'
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-image-a: 'postgres:14'
postgres-image-b: 'postgres:15'
postgres-auth: 'md5'
swift-image: 'swift:6.0-noble'
- postgres-image-a: 'postgres:16'
postgres-image-b: 'postgres:17'
postgres-auth: 'scram-sha-256'
swift-image: 'swift:6.0-jammy'
swift-image: 'swift:6.1-noble'
container: ${{ matrix.swift-image }}
runs-on: ubuntu-latest
services:
Expand Down Expand Up @@ -89,8 +89,8 @@ jobs:
fail-fast: false
matrix:
include:
- macos-version: macos-14
xcode-version: latest
- macos-version: macos-15
xcode-version: latest-stable
runs-on: ${{ matrix.macos-version }}
env:
LOG_LEVEL: debug
Expand All @@ -106,7 +106,7 @@ jobs:
run: |
brew upgrade || true
export PATH="$(brew --prefix)/opt/postgresql@16/bin:$PATH" PGDATA=/tmp/vapor-postgres-test PGUSER="${POSTGRES_USER_A}"
(brew unlink postgresql@14 || true) && brew install postgresql@16 && brew link --force postgresql@16
brew install postgresql@17 && brew link --force postgresql@17
initdb --locale=C --auth-host "scram-sha-256" -U "${POSTGRES_USER_A}" --pwfile=<(echo "${POSTGRES_PASSWORD_A}")
pg_ctl start --wait
PGPASSWORD="${POSTGRES_PASSWORD_A}" createdb -w -O "${POSTGRES_USER_A}" "${POSTGRES_DB_A}"
Expand Down
77 changes: 77 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"indentation" : {
"spaces" : 4
},
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineBreakBetweenDeclarationAttributes" : false,
"lineLength" : 150,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"reflowMultilineStringLiterals" : {
"never" : {
}
},
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : true,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"AvoidRetroactiveConformances" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyLinesOpeningClosingBraces" : false,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : true,
"UseExplicitNilCheckInConditions" : true,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : true,
"spacesBeforeEndOfLineComments" : 1,
"tabWidth" : 4,
"version" : 1
}
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:5.10
import PackageDescription

let package = Package(
Expand All @@ -13,15 +13,13 @@ let package = Package(
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
],
dependencies: [
.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: [
.target(
name: "FluentPostgresDriver",
dependencies: [
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "FluentSQL", package: "fluent-kit"),
.product(name: "PostgresKit", package: "postgres-kit"),
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/fluent-postgres-driver/assets/1130717/c2350b70-aaf1-43e1-ab79-86fc88ba8da4">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/fluent-postgres-driver/assets/1130717/dfc94dc2-281b-4e54-be86-549813496373">
<img src="https://github.com/vapor/fluent-postgres-driver/assets/1130717/dfc94dc2-281b-4e54-be86-549813496373" height="96" alt="FluentPostgresDriver">
</picture>
<img src="https://design.vapor.codes/images/vapor-fluentpostgresdriver.svg" height="96" alt="FluentPostgresDriver">
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/fluent-postgres-driver/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/fluent-postgres-driver/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/fluent-postgres-driver"><img src="https://img.shields.io/codecov/c/github/vapor/fluent-postgres-driver?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/swift510up.svg" alt="Swift 5.10+"></a>
</p>

<br>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Logging
import FluentKit
import AsyncKit
import NIOCore
import NIOSSL
import Foundation
import Logging
import NIOCore
import PostgresKit
import PostgresNIO

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
"fluentpsqldriver": "#336791",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-fluentpsqldriver) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-fluentpsqldriver)",
"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" }
},
"icons": { "technology": "/fluentpostgresdriver/images/vapor-fluentpostgresdriver-logo.svg" }
"icons": { "technology": "/fluentpostgresdriver/images/FluentPostgresDriver/vapor-fluentpostgresdriver-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
Expand Down
28 changes: 13 additions & 15 deletions Sources/FluentPostgresDriver/FluentPostgresConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Logging
import FluentKit
import AsyncKit
import NIOCore
import NIOSSL
import FluentKit
import Foundation
import Logging
import NIOCore
import PostgresKit
import PostgresNIO

Expand Down Expand Up @@ -31,7 +30,8 @@ extension DatabaseConfigurationFactory {
configuration: try .init(url: urlString),
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encodingContext: encodingContext, decodingContext: decodingContext,
encodingContext: encodingContext,
decodingContext: decodingContext,
sqlLogLevel: sqlLogLevel
)
}
Expand Down Expand Up @@ -59,7 +59,8 @@ extension DatabaseConfigurationFactory {
configuration: try .init(url: url),
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encodingContext: encodingContext, decodingContext: decodingContext,
encodingContext: encodingContext,
decodingContext: decodingContext,
sqlLogLevel: sqlLogLevel
)
}
Expand All @@ -81,22 +82,19 @@ extension DatabaseConfigurationFactory {
decodingContext: PostgresDecodingContext<some PostgresJSONDecoder>,
sqlLogLevel: Logger.Level = .debug
) -> DatabaseConfigurationFactory {
let configuration = FakeSendable(wrappedValue: configuration)

return .init {
.init {
FluentPostgresConfiguration(
configuration: configuration,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encodingContext: encodingContext, decodingContext: decodingContext,
encodingContext: encodingContext,
decodingContext: decodingContext,
sqlLogLevel: sqlLogLevel
)
}
}
}

fileprivate struct FakeSendable<T>: @unchecked Sendable { let wrappedValue: T }

/// We'd like to just default the context parameters of the "actual" method. Unfortunately, there are a few
/// cases involving the UNIX domain socket initalizer where usage can resolve to either the new
/// `SQLPostgresConfiguration`-based method or the deprecated `PostgresConfiguration`-based method, with no
Expand Down Expand Up @@ -170,22 +168,22 @@ extension DatabaseConfigurationFactory {
/// The actual concrete configuration type produced by a configuration factory.
struct FluentPostgresConfiguration<E: PostgresJSONEncoder, D: PostgresJSONDecoder>: DatabaseConfiguration {
var middleware: [any AnyModelMiddleware] = []
fileprivate let configuration: FakeSendable<SQLPostgresConfiguration>
fileprivate let configuration: SQLPostgresConfiguration
let maxConnectionsPerEventLoop: Int
let connectionPoolTimeout: TimeAmount
let encodingContext: PostgresEncodingContext<E>
let decodingContext: PostgresDecodingContext<D>
let sqlLogLevel: Logger.Level

func makeDriver(for databases: Databases) -> any DatabaseDriver {
let connectionSource = PostgresConnectionSource(sqlConfiguration: self.configuration.wrappedValue)
let connectionSource = PostgresConnectionSource(sqlConfiguration: self.configuration)
let elgPool = EventLoopGroupConnectionPool(
source: connectionSource,
maxConnectionsPerEventLoop: self.maxConnectionsPerEventLoop,
requestTimeout: self.connectionPoolTimeout,
on: databases.eventLoopGroup
)

return _FluentPostgresDriver(
pool: elgPool,
encodingContext: self.encodingContext,
Expand Down
Loading