Skip to content

Commit 4c0cddc

Browse files
committed
Add JSONB version to PostgreSQLJSONCustomConvertible
Fix bug "unsupported jsonb version number 123"
1 parent 4988607 commit 4c0cddc

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)