Skip to content

Commit a891777

Browse files
authored
Merge pull request vapor#66 from Sorix/fix_jsonb
Add JSONB version to PostgreSQLJSONCustomConvertible
2 parents 16c8f0b + 4c0cddc commit a891777

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/PostgreSQL/Data/PostgreSQLJSONCustomConvertible.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ extension PostgreSQLJSONCustomConvertible {
4242
guard let encodable = self as? Encodable else {
4343
fatalError("`\(Self.self)` is not `Encodable`.")
4444
}
45-
return try PostgreSQLData(
45+
46+
// JSONB requires version number in a first byte
47+
let jsonBVersion: [UInt8] = [0x01]
48+
let jsonData = try JSONEncoder().encode(EncoderWrapper(encodable))
49+
50+
return PostgreSQLData(
4651
type: .jsonb,
47-
format: .text,
48-
data: JSONEncoder().encode(EncoderWrapper(encodable))
52+
format: .binary,
53+
data: jsonBVersion + jsonData
4954
)
5055
}
5156
}

0 commit comments

Comments
 (0)