README.md

This commit is contained in:
Gwendal Roué committed 2015-07-03 12:34:32 +02:00
1 parent fe2a0c8e7f
commit 9c8a7f8103
1 file changed
+13 -5
+13 -5
View File
@@ -303,6 +303,7 @@ class Person : RowModel {
...
// Boring and not DRY, but straightforward and trivial:
override func updateFromDatabaseRow(row: Row) {
if row.hasColumn("id") {
id = row.value(named: "id")
@@ -333,7 +334,7 @@ Declare a **Primary Key** in order to fetch a specific row model:
```swift
class Person : RowModel {
...
override class var databasePrimaryKey: PrimaryKey {
return .SQLiteRowID("id")
}
@@ -361,9 +362,7 @@ We think that this is the killer feature of GRDB.swift :bowtie:
```swift
class PersonsViewController: UITableViewController {
let persons: [PersonViewModel]?
// Subclass Person, with an extra `petCount`:
// Private subclass of Person, with an extra `petCount`:
private class PersonViewModel : Person {
var petCount: Int?
@@ -377,6 +376,8 @@ class PersonsViewController: UITableViewController {
}
}
let persons: [PersonViewModel]?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
@@ -403,11 +404,16 @@ Those operations require two more methods:
```swift
class Person : RowModel {
...
// The table name:
override class var databaseTableName: String? {
return "persons"
}
// The saved values:
override var databaseDictionary: [String: DatabaseValue?] {
return [
"id": id,
@@ -443,6 +449,8 @@ try dbQueue.inTransaction { db in
class Person : RowModel {
...
// Before insertion, set creationDate if not set yet.
override func insert(db: Database) throws {
if creationDate == nil {
creationDate = NSDate()