@@ -4,12 +4,12 @@ fileprivate let jsonBVersionBytes: [UInt8] = [0x01]
44
55extension PostgresData {
66 public init ( jsonb jsonData: Data ) {
7- let jsonBDataBytes = [ UInt8] ( jsonData)
7+ let jsonBData = [ UInt8] ( jsonData)
88
99 var buffer = ByteBufferAllocator ( )
10- . buffer ( capacity: jsonBVersionBytes. count + jsonBDataBytes . count)
10+ . buffer ( capacity: jsonBVersionBytes. count + jsonBData . count)
1111 buffer. writeBytes ( jsonBVersionBytes)
12- buffer. writeBytes ( jsonBDataBytes )
12+ buffer. writeBytes ( jsonBData )
1313
1414 self . init ( type: . jsonb, formatCode: . binary, value: buffer)
1515 }
@@ -23,29 +23,31 @@ extension PostgresData {
2323 guard var value = self . value else {
2424 return nil
2525 }
26+ guard case . jsonb = self . type else {
27+ return nil
28+ }
2629
2730 guard let versionBytes = value. readBytes ( length: jsonBVersionBytes. count) , [ UInt8] ( versionBytes) == jsonBVersionBytes else {
2831 return nil
2932 }
3033
31- guard let dataBytes = value. readBytes ( length: value. readableBytes) else {
34+ guard let data = value. readBytes ( length: value. readableBytes) else {
3235 return nil
3336 }
3437
35- return Data ( dataBytes )
38+ return Data ( data )
3639 }
3740
3841 public func jsonb< T> ( as type: T . Type ) throws -> T ? where T: Decodable {
39- guard let jsonData = jsonb else {
42+ guard let data = jsonb else {
4043 return nil
4144 }
4245
43- return try JSONDecoder ( ) . decode ( T . self, from: jsonData )
46+ return try JSONDecoder ( ) . decode ( T . self, from: data )
4447 }
4548}
4649
47- public protocol PostgresJSONBCodable : Codable , PostgresDataConvertible {
48- }
50+ public protocol PostgresJSONBCodable : Codable , PostgresDataConvertible { }
4951
5052extension PostgresJSONBCodable {
5153 public static var postgresDataType : PostgresDataType {
0 commit comments