@@ -31,16 +31,17 @@ struct PostgreSQLDataDecoder {
31
31
32
32
func container< Key> ( keyedBy type: Key . Type ) throws -> KeyedDecodingContainer < Key > where Key : CodingKey {
33
33
let json : Data
34
- switch data. type {
35
- case . jsonb, . json:
36
- switch data. storage {
37
- case . binary( let data) :
38
- assert ( data [ data. startIndex] == 0x01 , " invalid JSONB data format " )
39
- json = data. advanced ( by: 1 )
40
- case . text( let string) : json = Data ( string. utf8)
41
- default : throw PostgreSQLError . decode ( JSON . self, from: data)
42
- }
43
- default : throw PostgreSQLError . decode ( JSON . self, from: data)
34
+ switch ( data. type, data. storage) {
35
+ case ( . jsonb, . binary( let data) ) :
36
+ assert ( data [ data. startIndex] == 0x01 , " invalid JSONB data format " )
37
+ json = data. advanced ( by: 1 )
38
+ case ( . json, . binary( let data) ) :
39
+ json = data
40
+ case ( . jsonb, . text( let string) ) ,
41
+ ( . json, . text( let string) ) :
42
+ json = Data ( string. utf8)
43
+ default :
44
+ throw PostgreSQLError . decode ( JSON . self, from: data)
44
45
}
45
46
let unwrapper = try JSONDecoder ( ) . decode ( DecoderUnwrapper . self, from: json)
46
47
return try unwrapper. decoder. container ( keyedBy: Key . self)
0 commit comments