-
-
Notifications
You must be signed in to change notification settings - Fork 87
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Currently PostgresData
values are serialized to the expected data format upon initialization. For example:
import Foundation
import PostgresNIO
let date = PostgresData(date: Date())
Upon initialization, date
contains TIMESTAMPTZ
formatted bytes ready for querying. The Date
supplied is discarded.
While this approach is simple, it has a draw back. Take the following query:
SELECT $1::JSON as "date"
If we attempted to pass the date
data from above to this query, we would get a warning followed by an error:
2019-10-18T15:12:42-0400 warning: bind $1 type (TIMESTAMPTZ) does not match expected parameter type (JSON)
2019-10-18T15:12:42-0400 error: invalid byte sequence for encoding "UTF8": 0x00 (report_invalid_encoding)
It makes sense that TIMESTAMPTZ
should not be convertible to JSON
, however, the original Date
object we had earlier does know how to convert to JSON. It can do so via Codable
and the JSONEncoder
.
If PostgresData
could support lazy serialization of Swift types, then we could support passing a Date
to this query dynamically.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request