github vapor/fluent-mysql-driver 4.0.0-rc.2.2
Add custom JSON encoder / decoder support

latest releases: 4.8.0, 4.7.1, 4.7.0...
pre-release6 years ago
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.

Don't miss a new fluent-mysql-driver release

NewReleases is sending notifications on new releases.