File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -3,19 +3,18 @@ import Foundation
3
3
public struct PostgresDataEncoder {
4
4
public init ( ) { }
5
5
6
- public func encode( _ type : Encodable ) throws -> PostgresData {
7
- if let custom = type as? PostgresDataConvertible {
8
- return custom. postgresData ?? . null
6
+ public func encode( _ value : Encodable ) throws -> PostgresData {
7
+ if let custom = value as? PostgresDataConvertible {
8
+ return custom. postgresData!
9
9
} else {
10
10
do {
11
11
let encoder = _Encoder ( )
12
- try type . encode ( to: encoder)
12
+ try value . encode ( to: encoder)
13
13
return encoder. data
14
14
} catch is DoJSON {
15
15
let json = JSONEncoder ( )
16
- let data = try json. encode ( Wrapper ( type ) )
16
+ let data = try json. encode ( Wrapper ( value ) )
17
17
var buffer = ByteBufferAllocator ( ) . buffer ( capacity: data. count)
18
- #warning("TODO: use nio foundation compat write")
19
18
buffer. writeBytes ( data)
20
19
return PostgresData ( type: . jsonb, value: buffer)
21
20
}
@@ -175,7 +174,11 @@ public struct PostgresDataEncoder {
175
174
}
176
175
177
176
mutating func encode< T> ( _ value: T ) throws where T : Encodable {
178
- try value. encode ( to: self . encoder)
177
+ if let value = value as? PostgresDataConvertible , let data = value. postgresData {
178
+ self . encoder. data = data
179
+ } else {
180
+ try value. encode ( to: self . encoder)
181
+ }
179
182
}
180
183
}
181
184
}
You can’t perform that action at this time.
0 commit comments