encode(to:)
Encodes the record into the provided persistence container.
func encode(to container: inout PersistenceContainer) throws
Throws
An error is thrown if the record can’t be encoded to its database representation.
In your implementation of this method, store in the container
argument all values that should be stored in database columns.
Primary key columns, if any, must be included.
For example:
struct Player: EncodableRecord {
var id: Int64?
var name: String?
func encode(to container: inout PersistenceContainer) {
container["id"] = id
container["name"] = name
}
}
It is undefined behavior to set different values for the same column. Column names are case insensitive, so defining both “name” and “NAME” is considered undefined behavior.