Skip to content

Commit c732dbf

Browse files
committed
add back encoder type
1 parent adfc112 commit c732dbf

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

Sources/FluentPostgreSQL/PostgreSQLData+Decoder.swift

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
internal struct PostgreSQLDataDecoder: SingleValueDecodingContainer {
2+
var codingPath: [CodingKey]
3+
var userInfo: [CodingUserInfoKey: Any]
4+
let data: PostgreSQLData
5+
init(data: PostgreSQLData) {
6+
self.data = data
7+
self.userInfo = [:]
8+
self.codingPath = []
9+
}
10+
11+
func decodeNil() -> Bool { return data.data == nil }
12+
func decode(_ type: Int.Type) throws -> Int { return try data.decode(Int.self) }
13+
func decode(_ type: Int8.Type) throws -> Int8 { return try data.decode(Int8.self) }
14+
func decode(_ type: Int16.Type) throws -> Int16 { return try data.decode(Int16.self) }
15+
func decode(_ type: Int32.Type) throws -> Int32 { return try data.decode(Int32.self) }
16+
func decode(_ type: Int64.Type) throws -> Int64 { return try data.decode(Int64.self) }
17+
func decode(_ type: UInt.Type) throws -> UInt { return try data.decode(UInt.self) }
18+
func decode(_ type: UInt8.Type) throws -> UInt8 { return try data.decode(UInt8.self) }
19+
func decode(_ type: UInt16.Type) throws -> UInt16 { return try data.decode(UInt16.self) }
20+
func decode(_ type: UInt32.Type) throws -> UInt32 { return try data.decode(UInt32.self) }
21+
func decode(_ type: UInt64.Type) throws -> UInt64 { return try data.decode(UInt64.self) }
22+
func decode(_ type: Double.Type) throws -> Double { return try data.decode(Double.self) }
23+
func decode(_ type: Float.Type) throws -> Float { return try data.decode(Float.self) }
24+
func decode(_ type: Bool.Type) throws -> Bool { return try data.decode(Bool.self) }
25+
func decode(_ type: String.Type) throws -> String { return try data.decode(String.self) }
26+
func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
27+
guard let convertible = type as? PostgreSQLDataCustomConvertible.Type else {
28+
throw PostgreSQLError(
29+
identifier: "convertible",
30+
reason: "Unsupported decodable type: \(type)",
31+
suggestedFixes: [
32+
"Conform \(type) to PostgreSQLDataCustomConvertible"
33+
]
34+
)
35+
}
36+
return try convertible.convertFromPostgreSQLData(data) as! T
37+
}
38+
}

Sources/FluentPostgreSQL/PostgreSQLDatabase+QuerySupporting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension PostgreSQLDatabase: QuerySupporting {
8282
// Run the query
8383
return try connection.query(sqlString, parameters) { row in
8484
let codableDict = row.mapValues { psqlData -> DecodableData in
85-
return .decoder(psqlData)
85+
return .decoder(PostgreSQLDataDecoder(data: psqlData))
8686
}
8787
do {
8888
let decoded = try CodableDataDecoder().decode(D.self, from: .dictionary(codableDict))

0 commit comments

Comments
 (0)