Skip to content

Commit 389e9b7

Browse files
committed
add FluentDatabases register method
1 parent 1c22eb4 commit 389e9b7

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Sources/FluentPostgresDriver/Postgres+Fluent.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import FluentSQL
22

3-
#warning("TODO: fix to allow conformance")
4-
struct SQLOutput: FluentOutput {
5-
let row: SQLRow
6-
7-
var description: String {
8-
return "\(self.row)"
9-
}
10-
11-
public init(row: SQLRow) {
12-
self.row = row
3+
extension FluentDatabaseID {
4+
public static var psql: FluentDatabaseID {
5+
return .init(string: "psql")
136
}
14-
15-
func decode<T>(field: String, as type: T.Type) throws -> T where T : Decodable {
16-
return try self.row.decode(column: field, as: T.self)
7+
}
8+
9+
extension FluentDatabases {
10+
public mutating func postgres(
11+
config: PostgresDatabase.Config,
12+
poolConfig: ConnectionPoolConfig = .init(),
13+
as id: FluentDatabaseID = .psql,
14+
isDefault: Bool = true
15+
) {
16+
let driver = PostgresDriver(connectionPool: .init(
17+
config: poolConfig,
18+
source: .init(config: config, on: self.eventLoop)
19+
))
20+
self.add(driver, as: id, isDefault: isDefault)
1721
}
1822
}
1923

@@ -37,8 +41,7 @@ public struct PostgresDriver: FluentDatabase {
3741
default: break
3842
}
3943
return connection.sqlQuery(sql) { row in
40-
let output = SQLOutput(row: row)
41-
try onOutput(output)
44+
try onOutput(row.fluentOutput)
4245
}
4346
}
4447
}

0 commit comments

Comments
 (0)