From c589080ef2bfbd6791bc4b299ae4995b459a5c82 Mon Sep 17 00:00:00 2001 From: Pascal Edmond Date: Fri, 29 Jan 2016 10:57:40 +0100 Subject: [PATCH] Person ordering --- DemoApps/GRDBDemoiOS/GRDBDemoiOS/Person.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Person.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Person.swift index b90c038ca..06e87ef7a 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Person.swift +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Person.swift @@ -45,6 +45,18 @@ class Person : Record { override func didInsertWithRowID(rowID: Int64, forColumn column: String?) { id = rowID } + + override func insert(db: Database) throws { + + // Basic Ordering + if self.position == 0 { + if let maxPosition = Int.fetchOne(db, "SELECT MAX(position) from persons") { + self.position = maxPosition + 1 + } + } + + try super.insert(db) + } } extension Person : Equatable { }