From 9c8a7f81036639fa51a977746d3c48367adc6c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 3 Jul 2015 12:34:32 +0200 Subject: [PATCH] README.md --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d5ec88529..d873766e2 100644 --- a/README.md +++ b/README.md @@ -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()