mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Update documentation in order to foster column enums
This commit is contained in:
1 parent
f2ae44384f
commit
d6f93afffe
1 file changed
+27
-36
@@ -2177,15 +2177,12 @@ extension Place : FetchableRecord {
|
||||
}
|
||||
```
|
||||
|
||||
Rows also accept keys of type `Column`:
|
||||
Rows also accept columns:
|
||||
|
||||
```swift
|
||||
extension Place : FetchableRecord {
|
||||
enum Columns {
|
||||
static let id = Column("id")
|
||||
static let title = Column("title")
|
||||
static let latitude = Column("latitude")
|
||||
static let longitude = Column("longitude")
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id, title, latitude, longitude
|
||||
}
|
||||
|
||||
init(row: Row) {
|
||||
@@ -2335,15 +2332,12 @@ try paris.insert(db)
|
||||
paris.id // some value
|
||||
```
|
||||
|
||||
Persistence containers also accept keys of type `Column`:
|
||||
Persistence containers also accept columns:
|
||||
|
||||
```swift
|
||||
extension Place : MutablePersistableRecord {
|
||||
enum Columns {
|
||||
static let id = Column("id")
|
||||
static let title = Column("title")
|
||||
static let latitude = Column("latitude")
|
||||
static let longitude = Column("longitude")
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id, title, latitude, longitude
|
||||
}
|
||||
|
||||
func encode(to container: inout PersistenceContainer) {
|
||||
@@ -2562,20 +2556,16 @@ class Place: Record {
|
||||
super.init()
|
||||
}
|
||||
|
||||
/// The table columns
|
||||
enum Columns {
|
||||
static let id = Column("id")
|
||||
static let title = Column("title")
|
||||
static let favorite = Column("favorite")
|
||||
static let latitude = Column("latitude")
|
||||
static let longitude = Column("longitude")
|
||||
}
|
||||
|
||||
/// The table name
|
||||
override class var databaseTableName: String {
|
||||
return "places"
|
||||
}
|
||||
|
||||
/// The table columns
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id, title, favorite, latitude, longitude
|
||||
}
|
||||
|
||||
/// Creates a record from a database row
|
||||
required init(row: Row) {
|
||||
id = row[Columns.id]
|
||||
@@ -2942,12 +2932,8 @@ Each one of the three examples below is correct. You will pick one or the other
|
||||
static let databaseTableName = "places"
|
||||
|
||||
/// The table columns
|
||||
enum Columns {
|
||||
static let id = Column("id")
|
||||
static let title = Column("title")
|
||||
static let favorite = Column("favorite")
|
||||
static let latitude = Column("latitude")
|
||||
static let longitude = Column("longitude")
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id, title, favorite, latitude, longitude
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2997,20 +2983,16 @@ Each one of the three examples below is correct. You will pick one or the other
|
||||
super.init()
|
||||
}
|
||||
|
||||
/// The table columns
|
||||
enum Columns {
|
||||
static let id = Column("id")
|
||||
static let title = Column("title")
|
||||
static let favorite = Column("favorite")
|
||||
static let latitude = Column("latitude")
|
||||
static let longitude = Column("longitude")
|
||||
}
|
||||
|
||||
/// The table name
|
||||
override class var databaseTableName: String {
|
||||
return "places"
|
||||
}
|
||||
|
||||
/// The table columns
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id, title, favorite, latitude, longitude
|
||||
}
|
||||
|
||||
/// Creates a record from a database row
|
||||
required init(row: Row) {
|
||||
id = row[Columns.id]
|
||||
@@ -3381,6 +3363,15 @@ let idColumn = Column("id")
|
||||
let nameColumn = Column("name")
|
||||
```
|
||||
|
||||
You can also declare column enums, if you prefer:
|
||||
|
||||
```swift
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id
|
||||
case name
|
||||
}
|
||||
```
|
||||
|
||||
You can now build requests with the following methods: `all`, `none`, `select`, `distinct`, `filter`, `matching`, `group`, `having`, `order`, `reversed`, `limit`. All those methods return another request, which you can further refine by applying another method: `Player.select(...).filter(...).order(...)`.
|
||||
|
||||
- `all()`, `none()`: the requests for all rows, or no row.
|
||||
|
||||
Reference in new issue
Block a user