Skip to content

Commit add0283

Browse files
committed
Run swift-format on most of the code
1 parent 1668189 commit add0283

9 files changed

+236
-182
lines changed

Sources/FluentPostgresDriver/Deprecations/FluentPostgresConfiguration+Deprecated.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import Logging
21
import FluentKit
3-
import AsyncKit
4-
import NIOCore
5-
import NIOSSL
62
import Foundation
3+
import Logging
4+
import NIOCore
75
import PostgresKit
86
import PostgresNIO
97

Sources/FluentPostgresDriver/FluentPostgresConfiguration.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import Logging
2-
import FluentKit
31
import AsyncKit
4-
import NIOCore
5-
import NIOSSL
2+
import FluentKit
63
import Foundation
4+
import Logging
5+
import NIOCore
76
import PostgresKit
87
import PostgresNIO
98

@@ -31,7 +30,8 @@ extension DatabaseConfigurationFactory {
3130
configuration: try .init(url: urlString),
3231
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
3332
connectionPoolTimeout: connectionPoolTimeout,
34-
encodingContext: encodingContext, decodingContext: decodingContext,
33+
encodingContext: encodingContext,
34+
decodingContext: decodingContext,
3535
sqlLogLevel: sqlLogLevel
3636
)
3737
}
@@ -59,7 +59,8 @@ extension DatabaseConfigurationFactory {
5959
configuration: try .init(url: url),
6060
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
6161
connectionPoolTimeout: connectionPoolTimeout,
62-
encodingContext: encodingContext, decodingContext: decodingContext,
62+
encodingContext: encodingContext,
63+
decodingContext: decodingContext,
6364
sqlLogLevel: sqlLogLevel
6465
)
6566
}
@@ -82,20 +83,21 @@ extension DatabaseConfigurationFactory {
8283
sqlLogLevel: Logger.Level = .debug
8384
) -> DatabaseConfigurationFactory {
8485
let configuration = FakeSendable(wrappedValue: configuration)
85-
86+
8687
return .init {
8788
FluentPostgresConfiguration(
8889
configuration: configuration,
8990
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
9091
connectionPoolTimeout: connectionPoolTimeout,
91-
encodingContext: encodingContext, decodingContext: decodingContext,
92+
encodingContext: encodingContext,
93+
decodingContext: decodingContext,
9294
sqlLogLevel: sqlLogLevel
9395
)
9496
}
9597
}
9698
}
9799

98-
fileprivate struct FakeSendable<T>: @unchecked Sendable { let wrappedValue: T }
100+
private struct FakeSendable<T>: @unchecked Sendable { let wrappedValue: T }
99101

100102
/// We'd like to just default the context parameters of the "actual" method. Unfortunately, there are a few
101103
/// cases involving the UNIX domain socket initalizer where usage can resolve to either the new
@@ -185,7 +187,7 @@ struct FluentPostgresConfiguration<E: PostgresJSONEncoder, D: PostgresJSONDecode
185187
requestTimeout: self.connectionPoolTimeout,
186188
on: databases.eventLoopGroup
187189
)
188-
190+
189191
return _FluentPostgresDriver(
190192
pool: elgPool,
191193
encodingContext: self.encodingContext,

Sources/FluentPostgresDriver/FluentPostgresDatabase.swift

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ struct _FluentPostgresDatabase<E: PostgresJSONEncoder, D: PostgresJSONDecoder> {
1616
extension _FluentPostgresDatabase: Database {
1717
func execute(
1818
query: DatabaseQuery,
19-
onOutput: @escaping @Sendable (any DatabaseOutput) -> ()
19+
onOutput: @escaping @Sendable (any DatabaseOutput) -> Void
2020
) -> EventLoopFuture<Void> {
2121
var expression = SQLQueryConverter(delegate: PostgresConverterDelegate()).convert(query)
22-
22+
2323
/// For `.create` query actions, we want to return the generated IDs, unless the `customIDKey` is the
2424
/// empty string, which we use as a very hacky signal for "we don't implement this for composite IDs yet".
2525
if case .create = query.action, query.customIDKey != .some(.string("")) {
2626
expression = SQLKit.SQLList([expression, SQLReturning(.init((query.customIDKey ?? .id).description))], separator: SQLRaw(" "))
2727
}
28-
28+
2929
return self.execute(sql: expression, { onOutput($0.databaseOutput()) })
3030
}
3131

3232
func execute(schema: DatabaseSchema) -> EventLoopFuture<Void> {
3333
let expression = SQLSchemaConverter(delegate: PostgresConverterDelegate()).convert(schema)
3434

35-
return self.execute(sql: expression,
35+
return self.execute(
36+
sql: expression,
3637
// N.B.: Don't fatalError() here; what're users supposed to do about it?
3738
{ self.logger.debug("Unexpected row returned from schema query: \($0)") }
3839
)
@@ -50,9 +51,11 @@ extension _FluentPostgresDatabase: Database {
5051
return self.eventLoop.makeSucceededFuture(())
5152
}
5253

53-
return self.eventLoop.flatten(e.createCases.map { create in
54-
self.alter(enum: e.name).add(value: create).run()
55-
})
54+
return self.eventLoop.flatten(
55+
e.createCases.map { create in
56+
self.alter(enum: e.name).add(value: create).run()
57+
}
58+
)
5659
case .delete:
5760
return self.drop(enum: e.name).run()
5861
}
@@ -64,10 +67,12 @@ extension _FluentPostgresDatabase: Database {
6467
}
6568
return self.withConnection { conn in
6669
guard let sqlConn = conn as? any SQLDatabase else {
67-
fatalError("""
70+
fatalError(
71+
"""
6872
Connection yielded by a Fluent+Postgres database is not also an SQLDatabase.
6973
This is a bug in Fluent; please report it at https://github.com/vapor/fluent-postgres-driver/issues
70-
""")
74+
"""
75+
)
7176
}
7277
return sqlConn.raw("BEGIN").run().flatMap {
7378
closure(conn).flatMap { result in
@@ -78,16 +83,22 @@ extension _FluentPostgresDatabase: Database {
7883
}
7984
}
8085
}
81-
86+
8287
func withConnection<T>(_ closure: @escaping @Sendable (any Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
8388
self.withConnection { (underlying: any PostgresDatabase) in
84-
closure(_FluentPostgresDatabase(
85-
database: underlying.sql(encodingContext: self.encodingContext, decodingContext: self.decodingContext, queryLogLevel: self.database.queryLogLevel),
86-
context: self.context,
87-
encodingContext: self.encodingContext,
88-
decodingContext: self.decodingContext,
89-
inTransaction: true
90-
))
89+
closure(
90+
_FluentPostgresDatabase(
91+
database: underlying.sql(
92+
encodingContext: self.encodingContext,
93+
decodingContext: self.decodingContext,
94+
queryLogLevel: self.database.queryLogLevel
95+
),
96+
context: self.context,
97+
encodingContext: self.encodingContext,
98+
decodingContext: self.decodingContext,
99+
inTransaction: true
100+
)
101+
)
91102
}
92103
}
93104
}
@@ -96,11 +107,11 @@ extension _FluentPostgresDatabase: TransactionControlDatabase {
96107
func beginTransaction() -> EventLoopFuture<Void> {
97108
self.raw("BEGIN").run()
98109
}
99-
110+
100111
func commitTransaction() -> EventLoopFuture<Void> {
101112
self.raw("COMMIT").run()
102113
}
103-
114+
104115
func rollbackTransaction() -> EventLoopFuture<Void> {
105116
self.raw("ROLLBACK").run()
106117
}
@@ -110,15 +121,15 @@ extension _FluentPostgresDatabase: SQLDatabase {
110121
var version: (any SQLDatabaseReportedVersion)? { self.database.version }
111122
var dialect: any SQLDialect { self.database.dialect }
112123
var queryLogLevel: Logger.Level? { self.database.queryLogLevel }
113-
114-
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> ()) -> EventLoopFuture<Void> {
124+
125+
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> Void) -> EventLoopFuture<Void> {
115126
self.database.execute(sql: query, onRow)
116127
}
117-
118-
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> ()) async throws {
128+
129+
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> Void) async throws {
119130
try await self.database.execute(sql: query, onRow)
120131
}
121-
132+
122133
func withSession<R>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R {
123134
try await self.database.withSession(closure)
124135
}
@@ -128,15 +139,17 @@ extension _FluentPostgresDatabase: PostgresDatabase {
128139
func send(_ request: any PostgresRequest, logger: Logger) -> EventLoopFuture<Void> {
129140
self.withConnection { $0.send(request, logger: logger) }
130141
}
131-
142+
132143
func withConnection<T>(_ closure: @escaping (PostgresConnection) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
133144
guard let psqlDb: any PostgresDatabase = self.database as? any PostgresDatabase else {
134-
fatalError("""
145+
fatalError(
146+
"""
135147
Connection yielded by a Fluent+Postgres database is not also a PostgresDatabase.
136148
This is a bug in Fluent; please report it at https://github.com/vapor/fluent-postgres-driver/issues
137-
""")
149+
"""
150+
)
138151
}
139-
152+
140153
return psqlDb.withConnection(closure)
141154
}
142155
}

Sources/FluentPostgresDriver/FluentPostgresDriver.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AsyncKit
2-
import NIOCore
3-
import Logging
42
import FluentKit
3+
import Logging
4+
import NIOCore
55
import PostgresKit
66

77
/// Marked `@unchecked Sendable` to silence warning about `PostgresConnectionSource`
@@ -10,7 +10,7 @@ struct _FluentPostgresDriver<E: PostgresJSONEncoder, D: PostgresJSONDecoder>: Da
1010
let encodingContext: PostgresEncodingContext<E>
1111
let decodingContext: PostgresDecodingContext<D>
1212
let sqlLogLevel: Logger.Level
13-
13+
1414
func makeDatabase(with context: DatabaseContext) -> any Database {
1515
_FluentPostgresDatabase(
1616
database: self.pool
@@ -23,11 +23,11 @@ struct _FluentPostgresDriver<E: PostgresJSONEncoder, D: PostgresJSONDecoder>: Da
2323
inTransaction: false
2424
)
2525
}
26-
26+
2727
func shutdown() {
2828
try? self.pool.syncShutdownGracefully()
2929
}
30-
30+
3131
func shutdownAsync() async {
3232
try? await self.pool.shutdownAsync()
3333
}

Sources/FluentPostgresDriver/PostgresConverterDelegate.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,50 @@ struct PostgresConverterDelegate: SQLConverterDelegate {
66
func customDataType(_ dataType: DatabaseSchema.DataType) -> (any SQLExpression)? {
77
switch dataType {
88
case .uuid:
9-
return SQLRaw("UUID")
9+
SQLRaw("UUID")
1010
case .bool:
11-
return SQLRaw("BOOL")
11+
SQLRaw("BOOL")
1212
case .data:
13-
return SQLRaw("BYTEA")
13+
SQLRaw("BYTEA")
1414
case .date:
15-
return SQLRaw("DATE")
15+
SQLRaw("DATE")
1616
case .datetime:
17-
return SQLRaw("TIMESTAMPTZ")
17+
SQLRaw("TIMESTAMPTZ")
1818
case .double:
19-
return SQLRaw("DOUBLE PRECISION")
19+
SQLRaw("DOUBLE PRECISION")
2020
case .dictionary:
21-
return SQLRaw("JSONB")
21+
SQLRaw("JSONB")
2222
case .array(of: let type):
2323
if let type = type, let dataType = self.customDataType(type) {
24-
return SQLArrayDataType(dataType: dataType)
24+
SQLArrayDataType(dataType: dataType)
2525
} else {
26-
return SQLRaw("JSONB")
26+
SQLRaw("JSONB")
2727
}
2828
case .enum(let value):
29-
return SQLIdentifier(value.name)
29+
SQLIdentifier(value.name)
3030
case .int8, .uint8:
31-
return SQLIdentifier("char")
31+
SQLIdentifier("char")
3232
case .int16, .uint16:
33-
return SQLRaw("SMALLINT")
33+
SQLRaw("SMALLINT")
3434
case .int32, .uint32:
35-
return SQLRaw("INT")
35+
SQLRaw("INT")
3636
case .int64, .uint64:
37-
return SQLRaw("BIGINT")
37+
SQLRaw("BIGINT")
3838
case .string:
39-
return SQLRaw("TEXT")
39+
SQLRaw("TEXT")
4040
case .time:
41-
return SQLRaw("TIME")
41+
SQLRaw("TIME")
4242
case .float:
43-
return SQLRaw("FLOAT")
43+
SQLRaw("FLOAT")
4444
case .custom:
45-
return nil
45+
nil
4646
}
4747
}
4848
}
4949

5050
private struct SQLArrayDataType: SQLExpression {
5151
let dataType: any SQLExpression
52-
52+
5353
func serialize(to serializer: inout SQLSerializer) {
5454
self.dataType.serialize(to: &serializer)
5555
serializer.write("[]")

0 commit comments

Comments
 (0)