Skip to content

Commit 9ba6313

Browse files
committed
Replaced PostgresRow:DatabaseRow with .databaseRow(using:) methods
1 parent 41cd1c7 commit 9ba6313

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Sources/PostgresKit/PostgresClient+SQL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension _PostgresSQLDatabase: SQLDatabase {
3232
return try self.database.query(sql, binds.map { encodable in
3333
return try self.encoder.encode(encodable)
3434
}) { row in
35-
onRow(row)
35+
onRow(row.sqlRow(using: self.decoder))
3636
}
3737
} catch {
3838
return self.eventLoop.makeFailedFuture(error)

Sources/PostgresKit/PostgresRow+SQL.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
extension PostgresRow: SQLRow {
2-
public func decode<D>(column: String, as type: D.Type) throws -> D where D : Decodable {
3-
guard let data = self.column(column) else {
1+
extension PostgresRow {
2+
public func sqlRow(using decoder: PostgresDecoder) -> SQLRow {
3+
return _PostgreSQLRow(row: self, decoder: decoder)
4+
}
5+
6+
public func sqlRow(using decoder: JSONDecoder = JSONDecoder()) -> SQLRow {
7+
return _PostgreSQLRow(row: self, decoder: PostgresDataDecoder(jsonDecoder: decoder))
8+
}
9+
}
10+
11+
private struct _PostgreSQLRow: SQLRow {
12+
let row: PostgresRow
13+
let decoder: PostgresDecoder
14+
15+
func decode<D>(column: String, as type: D.Type) throws -> D where D : Decodable {
16+
guard let data = self.row.column(column) else {
417
fatalError()
518
}
619
return try self.decoder.decode(D.self, from: data)

0 commit comments

Comments
 (0)