Last active
March 29, 2016 20:15
-
-
Save groue/8c09ef2d40777ea9f91d1cc20b250bec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GRDB | |
class Person: Record { | |
var id: Int64? | |
var name: String | |
var score: Int | |
init(name: String, score: Int) { | |
self.name = name | |
self.score = score | |
super.init() | |
} | |
// MARK: Record overrides | |
/// The table name | |
override class func databaseTableName() -> String { | |
return "persons" | |
} | |
/// Initialize from a database row | |
required init(_ row: Row) { | |
id = row.value(named: "id") | |
name = row.value(named: "name") | |
score = row.value(named: "score") | |
super.init(row) | |
} | |
/// The values persisted in the database | |
override var persistentDictionary: [String : DatabaseValueConvertible?] { | |
return [ | |
"id": id, | |
"name": name, | |
"score": score] | |
} | |
/// Update person ID after a successful insertion | |
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) { | |
id = rowID | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment