Skip to content

Commit 73529a6

Browse files
authored
Some minor cleanup (#99)
* Bump Swift minimum to 5.10, update CI and README, add .editorconfig and .swift-format * Apply swift-format * Adjust timeout in tests for the benefit of the Android tests
1 parent 6e3a5ff commit 73529a6

13 files changed

+205
-112
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*.swift]
2+
indent_style = space
3+
indent_size = 4
4+
tab_width = 4
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+

.github/workflows/test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ jobs:
1010
unit-tests:
1111
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
1212
secrets: inherit
13+
with:
14+
with_android: true

.swift-format

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentConditionalCompilationBlocks" : false,
6+
"indentSwitchCaseLabels" : false,
7+
"indentation" : {
8+
"spaces" : 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineBreakBetweenDeclarationAttributes" : false,
15+
"lineLength" : 150,
16+
"maximumBlankLines" : 1,
17+
"multiElementCollectionTrailingCommas" : true,
18+
"noAssignmentInExpressions" : {
19+
"allowedFunctions" : [
20+
]
21+
},
22+
"prioritizeKeepingFunctionOutputTogether" : false,
23+
"reflowMultilineStringLiterals" : {
24+
"never" : {
25+
}
26+
},
27+
"respectsExistingLineBreaks" : true,
28+
"rules" : {
29+
"AllPublicDeclarationsHaveDocumentation" : false,
30+
"AlwaysUseLiteralForEmptyCollectionInit" : true,
31+
"AlwaysUseLowerCamelCase" : true,
32+
"AmbiguousTrailingClosureOverload" : true,
33+
"AvoidRetroactiveConformances" : true,
34+
"BeginDocumentationCommentWithOneLineSummary" : false,
35+
"DoNotUseSemicolons" : true,
36+
"DontRepeatTypeInStaticProperties" : true,
37+
"FileScopedDeclarationPrivacy" : true,
38+
"FullyIndirectEnum" : true,
39+
"GroupNumericLiterals" : true,
40+
"IdentifiersMustBeASCII" : true,
41+
"NeverForceUnwrap" : false,
42+
"NeverUseForceTry" : false,
43+
"NeverUseImplicitlyUnwrappedOptionals" : false,
44+
"NoAccessLevelOnExtensionDeclaration" : true,
45+
"NoAssignmentInExpressions" : true,
46+
"NoBlockComments" : true,
47+
"NoCasesWithOnlyFallthrough" : true,
48+
"NoEmptyLinesOpeningClosingBraces" : false,
49+
"NoEmptyTrailingClosureParentheses" : true,
50+
"NoLabelsInCasePatterns" : true,
51+
"NoLeadingUnderscores" : false,
52+
"NoParensAroundConditions" : true,
53+
"NoPlaygroundLiterals" : true,
54+
"NoVoidReturnOnFunctionSignature" : true,
55+
"OmitExplicitReturns" : false,
56+
"OneCasePerLine" : true,
57+
"OneVariableDeclarationPerLine" : true,
58+
"OnlyOneTrailingClosureArgument" : true,
59+
"OrderedImports" : true,
60+
"ReplaceForEachWithForLoop" : true,
61+
"ReturnVoidInsteadOfEmptyTuple" : true,
62+
"TypeNamesShouldBeCapitalized" : true,
63+
"UseEarlyExits" : true,
64+
"UseExplicitNilCheckInConditions" : true,
65+
"UseLetInEveryBoundCaseVariable" : true,
66+
"UseShorthandTypeNames" : true,
67+
"UseSingleLinePropertyGetter" : true,
68+
"UseSynthesizedInitializer" : true,
69+
"UseTripleSlashForDocumentationComments" : true,
70+
"UseWhereClausesInForLoops" : false,
71+
"ValidateDocumentationComments" : false
72+
},
73+
"spacesAroundRangeFormationOperators" : true,
74+
"spacesBeforeEndOfLineComments" : 1,
75+
"tabWidth" : 4,
76+
"version" : 1
77+
}

Package.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
@@ -13,9 +13,9 @@ let package = Package(
1313
.library(name: "FluentSQLiteDriver", targets: ["FluentSQLiteDriver"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.49.0"),
17-
.package(url: "https://github.com/vapor/sqlite-kit.git", from: "4.5.1"),
18-
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
16+
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.51.0"),
17+
.package(url: "https://github.com/vapor/sqlite-kit.git", from: "4.5.2"),
18+
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.3"),
1919
],
2020
targets: [
2121
.target(

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<p align="center">
2-
<picture>
3-
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/fluent-sqlite-driver/assets/1130717/8ea4e505-ae30-4f94-982c-39c86c01754f">
4-
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/fluent-sqlite-driver/assets/1130717/9553b52f-7724-4d75-8a8b-5be564cd20d8">
5-
<img src="https://github.com/vapor/fluent-sqlite-driver/assets/1130717/9553b52f-7724-4d75-8a8b-5be564cd20d8" height="96" alt="FluentSQLiteDriver">
6-
</picture>
2+
<img src="https://design.vapor.codes/images/vapor-fluentsqlitedriver.svg" height="96" alt="FluentSQLiteDriver">
73
<br>
84
<br>
95
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
106
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
117
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
128
<a href="https://github.com/vapor/fluent-sqlite-driver/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/fluent-sqlite-driver/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
139
<a href="https://codecov.io/github/vapor/fluent-sqlite-driver"><img src="https://img.shields.io/codecov/c/github/vapor/fluent-sqlite-driver?style=plastic&logo=codecov&label=codecov"></a>
14-
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
10+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
1511
</p>
1612

1713
<br>

Sources/FluentSQLiteDriver/Docs.docc/theme-settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
"fluentsqlitedriver": "hsl(215, 45%, 58%)",
99
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-fluentsqlitedriver) 30%, #000 100%)",
1010
"documentation-intro-accent": "var(--color-fluentsqlitedriver)",
11+
"documentation-intro-eyebrow": "white",
12+
"documentation-intro-figure": "white",
13+
"documentation-intro-title": "white",
1114
"logo-base": { "dark": "#fff", "light": "#000" },
1215
"logo-shape": { "dark": "#000", "light": "#fff" },
1316
"fill": { "dark": "#000", "light": "#fff" }
1417
},
15-
"icons": { "technology": "/fluentsqlitedriver/images/vapor-fluentsqlitedriver-logo.svg" }
18+
"icons": { "technology": "/fluentsqlitedriver/images/FluentSQLiteDriver/vapor-fluentsqlitedriver-logo.svg" }
1619
},
1720
"features": {
1821
"quickNavigation": { "enable": true },

Sources/FluentSQLiteDriver/FluentSQLiteConfiguration.swift

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import NIO
2-
import FluentKit
3-
import SQLiteKit
41
import AsyncKit
2+
import FluentKit
53
import Logging
4+
import NIO
5+
import SQLiteKit
66

77
// Hint: Yes, I know what default arguments are. This ridiculous spelling out of each alternative avoids public API
88
// breakage from adding the defaults. And yes, `maxConnectionsPerEventLoop` is not forwarded on purpose, it's not
@@ -11,18 +11,22 @@ import Logging
1111

1212
extension DatabaseConfigurationFactory {
1313
/// Shorthand for ``sqlite(_:maxConnectionsPerEventLoop:connectionPoolTimeout:dataEncoder:dataDecoder:sqlLogLevel:)``.
14-
public static func sqlite(_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10)) -> Self {
14+
public static func sqlite(
15+
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10)
16+
) -> Self {
1517
self.sqlite(config, connectionPoolTimeout: connectionPoolTimeout, dataEncoder: .init(), dataDecoder: .init(), sqlLogLevel: .debug)
1618
}
1719
/// Shorthand for ``sqlite(_:maxConnectionsPerEventLoop:connectionPoolTimeout:dataEncoder:dataDecoder:sqlLogLevel:)``.
1820
public static func sqlite(
19-
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10), dataEncoder: SQLiteDataEncoder
21+
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10),
22+
dataEncoder: SQLiteDataEncoder
2023
) -> Self {
2124
self.sqlite(config, connectionPoolTimeout: connectionPoolTimeout, dataEncoder: dataEncoder, dataDecoder: .init(), sqlLogLevel: .debug)
2225
}
2326
/// Shorthand for ``sqlite(_:maxConnectionsPerEventLoop:connectionPoolTimeout:dataEncoder:dataDecoder:sqlLogLevel:)``.
2427
public static func sqlite(
25-
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10), dataDecoder: SQLiteDataDecoder
28+
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10),
29+
dataDecoder: SQLiteDataDecoder
2630
) -> Self {
2731
self.sqlite(config, connectionPoolTimeout: connectionPoolTimeout, dataEncoder: .init(), dataDecoder: dataDecoder, sqlLogLevel: .debug)
2832
}
@@ -35,7 +39,8 @@ extension DatabaseConfigurationFactory {
3539
}
3640
/// Shorthand for ``sqlite(_:maxConnectionsPerEventLoop:connectionPoolTimeout:dataEncoder:dataDecoder:sqlLogLevel:)``.
3741
public static func sqlite(
38-
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10), sqlLogLevel: Logger.Level?
42+
_ config: SQLiteConfiguration = .memory, maxConnectionsPerEventLoop: Int = 1, connectionPoolTimeout: TimeAmount = .seconds(10),
43+
sqlLogLevel: Logger.Level?
3944
) -> Self {
4045
self.sqlite(config, connectionPoolTimeout: connectionPoolTimeout, dataEncoder: .init(), dataDecoder: .init(), sqlLogLevel: sqlLogLevel)
4146
}

Sources/FluentSQLiteDriver/FluentSQLiteDatabase.swift

+46-45
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import FluentKit
12
import FluentSQL
2-
import SQLiteKit
33
import NIOCore
4-
import SQLiteNIO
54
import SQLKit
6-
import FluentKit
5+
import SQLiteKit
6+
import SQLiteNIO
77

88
struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase {
99
let database: any SQLiteDatabase
@@ -12,28 +12,27 @@ struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase {
1212
let dataDecoder: SQLiteDataDecoder
1313
let queryLogLevel: Logger.Level?
1414
let inTransaction: Bool
15-
15+
1616
private func adjustFluentQuery(_ original: DatabaseQuery, _ converted: any SQLExpression) -> any SQLExpression {
1717
/// For `.create` query actions, we want to return the generated IDs, unless the `customIDKey` is the
1818
/// empty string, which we use as a very hacky signal for "we don't implement this for composite IDs yet".
19-
if case .create = original.action, original.customIDKey != .some(.string("")) {
20-
return SQLKit.SQLList([converted, SQLReturning(.init((original.customIDKey ?? .id).description))], separator: SQLRaw(" "))
21-
} else {
19+
guard case .create = original.action, original.customIDKey != .some(.string("")) else {
2220
return converted
2321
}
22+
return SQLKit.SQLList([converted, SQLReturning(.init((original.customIDKey ?? .id).description))], separator: SQLRaw(" "))
2423
}
25-
24+
2625
// Database
27-
28-
func execute(query: DatabaseQuery, onOutput: @escaping @Sendable (any DatabaseOutput) -> ()) -> EventLoopFuture<Void> {
26+
27+
func execute(query: DatabaseQuery, onOutput: @escaping @Sendable (any DatabaseOutput) -> Void) -> EventLoopFuture<Void> {
2928
/// SQLiteKit will handle applying the configured data decoder to each row when providing `SQLRow`s.
30-
return self.execute(
29+
self.execute(
3130
sql: self.adjustFluentQuery(query, SQLQueryConverter(delegate: SQLiteConverterDelegate()).convert(query)),
3231
{ onOutput($0.databaseOutput()) }
3332
)
3433
}
35-
36-
func execute(query: DatabaseQuery, onOutput: @escaping @Sendable (any DatabaseOutput) -> ()) async throws {
34+
35+
func execute(query: DatabaseQuery, onOutput: @escaping @Sendable (any DatabaseOutput) -> Void) async throws {
3736
try await self.execute(
3837
sql: self.adjustFluentQuery(query, SQLQueryConverter(delegate: SQLiteConverterDelegate()).convert(query)),
3938
{ onOutput($0.databaseOutput()) }
@@ -42,20 +41,22 @@ struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase {
4241

4342
func execute(schema: DatabaseSchema) -> EventLoopFuture<Void> {
4443
var schema = schema
45-
44+
4645
if schema.action == .update {
47-
schema.updateFields = schema.updateFields.filter { switch $0 { // Filter out enum updates.
48-
case .dataType(_, .enum(_)): return false
49-
default: return true
50-
} }
46+
schema.updateFields = schema.updateFields.filter {
47+
switch $0 { // Filter out enum updates.
48+
case .dataType(_, .enum(_)): false
49+
default: true
50+
}
51+
}
5152
guard schema.createConstraints.isEmpty, schema.updateFields.isEmpty, schema.deleteConstraints.isEmpty else {
5253
return self.eventLoop.makeFailedFuture(FluentSQLiteUnsupportedAlter())
5354
}
5455
if schema.createFields.isEmpty, schema.deleteFields.isEmpty { // If there were only enum updates, bail out.
5556
return self.eventLoop.makeSucceededFuture(())
5657
}
5758
}
58-
59+
5960
return self.execute(
6061
sql: SQLSchemaConverter(delegate: SQLiteConverterDelegate()).convert(schema),
6162
{ self.logger.debug("Unexpected row returned from schema query: \($0)") }
@@ -65,30 +66,29 @@ struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase {
6566
func execute(enum: DatabaseEnum) -> EventLoopFuture<Void> {
6667
self.eventLoop.makeSucceededFuture(())
6768
}
68-
69+
6970
func withConnection<T>(_ closure: @escaping @Sendable (any Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
7071
self.eventLoop.makeFutureWithTask { try await self.withConnection { try await closure($0).get() } }
7172
}
72-
73+
7374
func withConnection<T>(_ closure: @escaping @Sendable (any Database) async throws -> T) async throws -> T {
7475
try await self.withConnection {
75-
try await closure(FluentSQLiteDatabase(
76-
database: $0,
77-
context: self.context,
78-
dataEncoder: self.dataEncoder,
79-
dataDecoder: self.dataDecoder,
80-
queryLogLevel: self.queryLogLevel,
81-
inTransaction: self.inTransaction
82-
))
76+
try await closure(
77+
FluentSQLiteDatabase(
78+
database: $0,
79+
context: self.context,
80+
dataEncoder: self.dataEncoder,
81+
dataDecoder: self.dataDecoder,
82+
queryLogLevel: self.queryLogLevel,
83+
inTransaction: self.inTransaction
84+
))
8385
}
8486
}
85-
87+
8688
func transaction<T>(_ closure: @escaping @Sendable (any Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
87-
self.inTransaction ?
88-
closure(self) :
89-
self.eventLoop.makeFutureWithTask { try await self.transaction { try await closure($0).get() } }
89+
self.inTransaction ? closure(self) : self.eventLoop.makeFutureWithTask { try await self.transaction { try await closure($0).get() } }
9090
}
91-
91+
9292
func transaction<T>(_ closure: @escaping @Sendable (any Database) async throws -> T) async throws -> T {
9393
guard !self.inTransaction else {
9494
return try await closure(self)
@@ -103,11 +103,11 @@ struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase {
103103
queryLogLevel: self.queryLogLevel,
104104
inTransaction: true
105105
)
106-
106+
107107
try await db.raw("BEGIN TRANSACTION").run()
108108
do {
109109
let result = try await closure(db)
110-
110+
111111
try await db.raw("COMMIT TRANSACTION").run()
112112
return result
113113
} catch {
@@ -116,31 +116,32 @@ struct FluentSQLiteDatabase: Database, SQLDatabase, SQLiteDatabase {
116116
}
117117
}
118118
}
119-
119+
120120
// SQLDatabase
121121

122122
var dialect: any SQLDialect {
123123
self.database.sql(encoder: self.dataEncoder, decoder: self.dataDecoder, queryLogLevel: self.queryLogLevel).dialect
124124
}
125-
125+
126126
var version: (any SQLDatabaseReportedVersion)? {
127127
self.database.sql(encoder: self.dataEncoder, decoder: self.dataDecoder, queryLogLevel: self.queryLogLevel).version
128128
}
129-
130-
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> ()) -> EventLoopFuture<Void> {
129+
130+
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> Void) -> EventLoopFuture<Void> {
131131
self.database.sql(encoder: self.dataEncoder, decoder: self.dataDecoder, queryLogLevel: self.queryLogLevel).execute(sql: query, onRow)
132132
}
133-
134-
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> ()) async throws {
135-
try await self.database.sql(encoder: self.dataEncoder, decoder: self.dataDecoder, queryLogLevel: self.queryLogLevel).execute(sql: query, onRow)
133+
134+
func execute(sql query: any SQLExpression, _ onRow: @escaping @Sendable (any SQLRow) -> Void) async throws {
135+
try await self.database.sql(encoder: self.dataEncoder, decoder: self.dataDecoder, queryLogLevel: self.queryLogLevel).execute(
136+
sql: query, onRow)
136137
}
137-
138+
138139
func withSession<R>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R {
139140
try await self.database.sql(encoder: self.dataEncoder, decoder: self.dataDecoder, queryLogLevel: self.queryLogLevel).withSession(closure)
140141
}
141142

142143
// SQLiteDatabase
143-
144+
144145
func query(_ query: String, _ binds: [SQLiteData], logger: Logger, _ onRow: @escaping @Sendable (SQLiteRow) -> Void) -> EventLoopFuture<Void> {
145146
self.withConnection { $0.query(query, binds, logger: logger, onRow) }
146147
}

Sources/FluentSQLiteDriver/FluentSQLiteDriver.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import NIOCore
2-
import FluentKit
31
@preconcurrency import AsyncKit
4-
import SQLiteNIO
5-
import SQLiteKit
2+
import FluentKit
63
import Logging
4+
import NIOCore
5+
import SQLiteKit
6+
import SQLiteNIO
77

88
struct FluentSQLiteDriver: DatabaseDriver {
99
let pool: EventLoopGroupConnectionPool<SQLiteConnectionSource>
@@ -29,7 +29,7 @@ struct FluentSQLiteDriver: DatabaseDriver {
2929
func shutdown() {
3030
try? self.pool.syncShutdownGracefully()
3131
}
32-
32+
3333
func shutdownAsync() async {
3434
try? await self.pool.shutdownAsync()
3535
}

0 commit comments

Comments
 (0)