Foster columns gathered in an enum

This commit is contained in:
Gwendal Roué authored and Gwendal Roué committed 2017-06-20 07:54:19 +02:00
1 parent f750cee594
commit 2459b4e56f
2 files changed
+40 -16

No files matched your search

+20
View File
@@ -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.
+20 -16
View File
@@ -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
}
}
```