Skip to content

Commit 09d698e

Browse files
committed
Make db config more concise
1 parent 5ca07f6 commit 09d698e

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

Sources/FluentSQLiteDriver/Exports.swift

-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
@_exported import FluentKit
22
@_exported import SQLiteKit
33

4-
// TODO: deprecate
5-
extension Databases {
6-
public func sqlite(
7-
configuration: SQLiteConfiguration = .init(storage: .memory),
8-
maxConnectionsPerEventLoop: Int = 1,
9-
as id: DatabaseID = .sqlite
10-
) {
11-
self.use(
12-
.sqlite(
13-
configuration: configuration,
14-
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
15-
),
16-
as: id
17-
)
18-
}
19-
}
20-
214
extension DatabaseID {
225
public static var sqlite: DatabaseID {
236
return .init(string: "sqlite")

Sources/FluentSQLiteDriver/FluentSQLiteDriver.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
extension DatabaseDriverFactory {
22
public static func sqlite(
3-
file: String,
3+
_ configuration: SQLiteConfiguration = .init(storage: .memory),
44
maxConnectionsPerEventLoop: Int = 1
5-
) -> DatabaseDriverFactory {
6-
.sqlite(
7-
configuration: .init(file: file),
8-
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
9-
)
10-
}
11-
12-
public static func sqlite(
13-
configuration: SQLiteConfiguration = .init(storage: .memory),
14-
maxConnectionsPerEventLoop: Int = 1
15-
) -> DatabaseDriverFactory {
16-
return DatabaseDriverFactory { databases in
5+
) -> Self {
6+
return .init { databases in
177
let db = SQLiteConnectionSource(
188
configuration: configuration,
199
threadPool: databases.threadPool
@@ -28,6 +18,16 @@ extension DatabaseDriverFactory {
2818
}
2919
}
3020

21+
extension SQLiteConfiguration {
22+
public static func file(_ path: String) -> Self {
23+
.init(storage: .file(path: path))
24+
}
25+
26+
public static var memory: Self {
27+
.init(storage: .memory)
28+
}
29+
}
30+
3131
struct _ConnectionPoolSQLiteDatabase {
3232
let pool: EventLoopConnectionPool<SQLiteConnectionSource>
3333
let logger: Logger

Tests/FluentSQLiteDriverTests/FluentSQLiteDriverTests.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ final class FluentSQLiteDriverTests: XCTestCase {
160160
try self.benchmarker.testDuplicatedUniquePropertyName()
161161
}
162162

163+
func testRange() throws {
164+
try self.benchmarker.testRange()
165+
}
166+
163167
var benchmarker: FluentBenchmarker {
164168
return .init(database: self.database)
165169
}
@@ -181,10 +185,7 @@ final class FluentSQLiteDriverTests: XCTestCase {
181185
self.threadPool = .init(numberOfThreads: 2)
182186
self.threadPool.start()
183187
self.dbs = Databases(threadPool: self.threadPool, on: self.eventLoopGroup)
184-
self.dbs.sqlite(
185-
configuration: .init(storage: .memory),
186-
maxConnectionsPerEventLoop: 2
187-
)
188+
self.dbs.use(.sqlite(.memory), as: .sqlite)
188189
}
189190

190191
override func tearDown() {

0 commit comments

Comments
 (0)