EncodableRecord
A type that can encode itself in a database row.
protocol EncodableRecord
Browse conforming typesTo conform to EncodableRecord
, provide an implementation for the encode(to:)
method. This implementation is ready-made for Encodable
types.
Most of the time, your record types will get EncodableRecord
conformance through the MutablePersistableRecord
or PersistableRecord
protocols, which provide persistence methods.
Encoding a Database Row
func encode(to: inout PersistenceContainer
) throws Encodes the record into the provided persistence container.
struct PersistenceContainer
A container for database values to store in a database row.
Configuring Persistence for the Standard Encodable Protocol
static var databaseColumnEncodingStrategy: DatabaseColumnEncodingStrategy
The strategy for converting coding keys to column names.
databaseDataEncodingStrategy(for:)
databaseDateEncodingStrategy(for:)
databaseJSONEncoder(for:)-6x62c
databaseUUIDEncodingStrategy(for:)
static var databaseEncodingUserInfo: [CodingUserInfoKey : Any]
Contextual information made available to the
Encodable.encode(to:)
method.enum DatabaseColumnEncodingStrategy
DatabaseColumnEncodingStrategy
specifies howEncodableRecord
types that also adopt the standardEncodable
protocol encode their coding keys into database columns in the default doc:/documentation/GRDB/EncodableRecord/encode(to:)-1mrt implementation.enum DatabaseDataEncodingStrategy
DatabaseDataEncodingStrategy
specifies howEncodableRecord
types that also adopt the standardEncodable
protocol encode theirData
properties in the default doc:/documentation/GRDB/EncodableRecord/encode(to:)-1mrt implementation.enum DatabaseDateEncodingStrategy
DatabaseDateEncodingStrategy
specifies howEncodableRecord
types that also adopt the standardEncodable
protocol encode theirDate
properties in the default doc:/documentation/GRDB/EncodableRecord/encode(to:)-1mrt implementation.enum DatabaseUUIDEncodingStrategy
DatabaseUUIDEncodingStrategy
specifies howEncodableRecord
types that also adopt the standardEncodable
protocol encode theirUUID
properties in the default doc:/documentation/GRDB/EncodableRecord/encode(to:)-1mrt implementation.
Converting a Record to a Dictionary
var databaseDictionary: [String : DatabaseValue]
A dictionary whose keys are the columns encoded in the doc:/documentation/GRDB/EncodableRecord/encode(to:)-k9pf method.
Comparing Records
func databaseChanges(from: some EncodableRecord
) throws -> [String : DatabaseValue] Returns a dictionary of values changed from the other record.
func databaseChanges(modify: (inout Self) throws -> Void
) throws -> [String : DatabaseValue] Modifies the record according to the provided
modify
closure, and returns a dictionary of changed values.func databaseEquals(Self
) -> Bool Returns a boolean indicating whether this record and the other record have the same database representation.