File tree 3 files changed +7
-14
lines changed
3 files changed +7
-14
lines changed Original file line number Diff line number Diff line change 36
36
- run : swift test --enable-test-discovery --sanitize=thread
37
37
fluent :
38
38
container :
39
- image : vapor/swift:5.1
39
+ image : vapor/swift:5.2
40
40
services :
41
41
psql :
42
42
image : postgres
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ public final class PostgresDataDecoder {
56
56
}
57
57
58
58
func unkeyedContainer( ) throws -> UnkeyedDecodingContainer {
59
- print ( self . data. type)
60
59
guard let data = self . data. array else {
61
60
throw Error . unexpectedDataType ( self . data. type, expected: " array " )
62
61
}
@@ -108,15 +107,7 @@ public final class PostgresDataDecoder {
108
107
mutating func decode< T> ( _ type: T . Type ) throws -> T where T : Decodable {
109
108
defer { self . currentIndex += 1 }
110
109
let data = self . data [ self . currentIndex]
111
- let jsonData : Data
112
- if let jsonb = data. jsonb {
113
- jsonData = jsonb
114
- } else if let json = data. json {
115
- jsonData = json
116
- } else {
117
- throw Error . unexpectedDataType ( data. type, expected: " json " )
118
- }
119
- return try self . json. decode ( T . self, from: jsonData)
110
+ return try PostgresDataDecoder ( json: self . json) . decode ( T . self, from: data)
120
111
}
121
112
122
113
mutating func nestedContainer< NestedKey> (
Original file line number Diff line number Diff line change @@ -8,15 +8,17 @@ public final class PostgresDataEncoder {
8
8
}
9
9
10
10
public func encode( _ value: Encodable ) throws -> PostgresData {
11
- if let custom = value as? PostgresDataConvertible {
12
- return custom . postgresData!
11
+ if let custom = value as? PostgresDataConvertible , let data = custom . postgresData {
12
+ return data
13
13
} else {
14
14
let context = _Context ( )
15
15
try value. encode ( to: _Encoder ( context: context) )
16
16
if let value = context. value {
17
17
return value
18
18
} else if let array = context. array {
19
- return PostgresData ( array: array, elementType: . jsonb)
19
+ let elementType = array. first? . type ?? . jsonb
20
+ assert ( array. filter { $0. type != elementType } . isEmpty, " Array does not contain all: \( elementType) " )
21
+ return PostgresData ( array: array, elementType: elementType)
20
22
} else {
21
23
return try PostgresData ( jsonb: self . json. encode ( _Wrapper ( value) ) )
22
24
}
You can’t perform that action at this time.
0 commit comments