Add custom JSON encoder / decoder support
Pre-release
Pre-release
This patch was authored and released by @tanner0101.
Adds support for configuring which JSON coders MySQL uses when serializing nested data to the database (#189).
// Setup custom JSON coders that use unix timestamps
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .secondsSince1970
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
// Configure MySQL database.
app.databaes.use(.mysql(
configuration: ...,
encoder: MySQLDataEncoder(json: encoder),
decoder: MySQLDataDecoder(json: decoder)
))Note that for dates specifically, you can use @Timestamp formats to configure formatting per field.