Skip to content

Commit 55778c6

Browse files
committed
small fixes
1 parent 92782b6 commit 55778c6

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

Sources/FluentProvider/Droplet/Droplet+Storage.swift

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import Vapor
44
private let fluentDatabaseKey = "fluent-vapor-database"
55

66
extension Droplet {
7-
internal var database: Database?{
7+
public internal(set) var database: Database? {
88
get {
99
return storage[fluentDatabaseKey] as? Database
1010
}
1111
set {
1212
storage[fluentDatabaseKey] = newValue
1313
}
1414
}
15-
16-
17-
func assertDatabase() throws -> Database {
15+
16+
17+
public func assertDatabase() throws -> Database {
1818
guard let database = self.database else {
1919
throw FluentProviderError.noDatabase
2020
}
@@ -26,3 +26,32 @@ extension Droplet {
2626
public enum FluentProviderError: Error {
2727
case noDatabase
2828
}
29+
30+
extension FluentProviderError: Debuggable {
31+
public var reason: String {
32+
switch self {
33+
case .noDatabase:
34+
return "No database has been configured."
35+
}
36+
}
37+
38+
public var identifier: String {
39+
switch self {
40+
case .noDatabase:
41+
return "noDatabase"
42+
}
43+
}
44+
45+
public var possibleCauses: [String] {
46+
switch self {
47+
case .noDatabase:
48+
return [
49+
"You have not added the `MySQLProvider.Provider` to your Droplet."
50+
]
51+
}
52+
}
53+
54+
public var suggestedFixes: [String] {
55+
return []
56+
}
57+
}

Sources/FluentProvider/Provider.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ public final class Provider: Vapor.Provider {
138138
// add configurable driver types, this must
139139
// come before the preparation calls
140140
let driver = try drop.config.resolveDriver()
141-
let database = Database(driver)
141+
142+
let database: Database
143+
if let maxConnections = drop.config["fluent", "maxConnections"]?.int {
144+
database = Database(driver, maxConnections: maxConnections)
145+
} else {
146+
database = Database(driver)
147+
}
148+
142149
drop.database = database
143150

144151
if let m = self.migrationEntityName {

0 commit comments

Comments
 (0)