Skip to content

Commit

Permalink
Merge pull request #66 from Sorix/fix_jsonb
Browse files Browse the repository at this point in the history
Add JSONB version to PostgreSQLJSONCustomConvertible
  • Loading branch information
tanner0101 authored May 30, 2018
2 parents 16c8f0b + 4c0cddc commit a891777
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/PostgreSQL/Data/PostgreSQLJSONCustomConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ extension PostgreSQLJSONCustomConvertible {
guard let encodable = self as? Encodable else {
fatalError("`\(Self.self)` is not `Encodable`.")
}
return try PostgreSQLData(

// JSONB requires version number in a first byte
let jsonBVersion: [UInt8] = [0x01]
let jsonData = try JSONEncoder().encode(EncoderWrapper(encodable))

return PostgreSQLData(
type: .jsonb,
format: .text,
data: JSONEncoder().encode(EncoderWrapper(encodable))
format: .binary,
data: jsonBVersion + jsonData
)
}
}
Expand Down

0 comments on commit a891777

Please sign in to comment.