Skip to content

Instantly share code, notes, and snippets.

@groue
Last active March 29, 2016 20:15
Show Gist options
  • Save groue/8c09ef2d40777ea9f91d1cc20b250bec to your computer and use it in GitHub Desktop.
Save groue/8c09ef2d40777ea9f91d1cc20b250bec to your computer and use it in GitHub Desktop.
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