diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e86270c..fe1826c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,26 @@ Release Notes + } } ``` + + Persistence containers can handle keys of type Column: + + ```swift + struct Player : MutablePersistable { + let name: String + let score: Int + + enum Columns { + static let name = Column("name") + static let score = Column("score") + } + + func encode(to container: inout PersistenceContainer) { + container[Columns.name] = name + container[Columns.score] = score + } + } + ``` + - `TypedRequest.Fetched` associated type has been replaced by `TypedRequest.RowDecoder`, because the type of the values fetched by a typed request is not meant to be identical to the type that decode database rows. diff --git a/README.md b/README.md index 4f991e13a..4c77186bf 100644 --- a/README.md +++ b/README.md @@ -1870,17 +1870,19 @@ Rows also accept keys of type `Column`: ```swift extension PointOfInterest : RowConvertible { - static let idColumn = Column("id") - static let titleColumn = Column("title") - static let latitudeColumn = Column("latitude") - static let longitudeColumn = Column("longitude") + enum Columns { + static let id = Column("id") + static let title = Column("title") + static let latitude = Column("latitude") + static let longitude = Column("longitude") + } init(row: Row) { - id = row.value(PointOfInterest.idColumn) - title = row.value(PointOfInterest.titleColumn) + id = row.value(Columns.id) + title = row.value(Columns.title) coordinate = CLLocationCoordinate2DMake( - row.value(PointOfInterest.latitudeColumn), - row.value(PointOfInterest.longitudeColumn)) + row.value(Columns.latitude), + row.value(Columns.longitude)) } } ``` @@ -2051,16 +2053,18 @@ Persistence containers also accept keys of type `Column`: ```swift extension PointOfInterest : MutablePersistable { - static let idColumn = Column("id") - static let titleColumn = Column("title") - static let latitudeColumn = Column("latitude") - static let longitudeColumn = Column("longitude") + enum Columns { + static let id = Column("id") + static let title = Column("title") + static let latitude = Column("latitude") + static let longitude = Column("longitude") + } func encode(to container: inout PersistenceContainer) { - container[PointOfInterest.idColumn] = id - container[PointOfInterest.titleColumn] = title - container[PointOfInterest.latitudeColumn] = coordinate.latitude - container[PointOfInterest.longitudeColumn] = coordinate.longitude + container[Columns.id] = id + container[Columns.title] = title + container[Columns.latitude] = coordinate.latitude + container[Columns.longitude] = coordinate.longitude } } ```