From c7ad60522d0f9af4869ea3aee034354aecf01180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 11 Mar 2016 14:30:28 +0100 Subject: [PATCH] Modernize Record.playground --- Playgrounds/Record.playground/Contents.swift | 23 ++++++++------------ 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Playgrounds/Record.playground/Contents.swift b/Playgrounds/Record.playground/Contents.swift index 22949f0c8..27e4dd506 100644 --- a/Playgrounds/Record.playground/Contents.swift +++ b/Playgrounds/Record.playground/Contents.swift @@ -99,18 +99,16 @@ try dbQueue.inDatabase { db in //: ## Fetching Records -dbQueue.inDatabase { db in //: Fetch records from the database: - let allPersons = Person.fetchAll(db) - +let allPersons = Person.fetchAll(dbQueue) + //: Fetch record by primary key: - let person = Person.fetchOne(db, key: arthur.id)! - person.fullName +let person = Person.fetchOne(dbQueue, key: arthur.id)! +person.fullName //: Fetch persons with an SQL query: - let millers = Person.fetchAll(db, "SELECT * FROM persons WHERE lastName = ?", arguments: ["Miller"]) - millers.first!.fullName -} +let millers = Person.fetchAll(dbQueue, "SELECT * FROM persons WHERE lastName = ?", arguments: ["Miller"]) +millers.first!.fullName //: To fetch persons using the query interface, you need some colums that can filter or sort: @@ -120,11 +118,8 @@ struct Col { static let lastName = SQLColumn("lastName") } -dbQueue.inDatabase { db in - //: Sort - let personsSortedByName = Person.order(Col.firstName, Col.lastName).fetchAll(db) - +let personsSortedByName = Person.order(Col.firstName, Col.lastName).fetchAll(dbQueue) + //: Filter - let millers = Person.filter(Col.lastName == "Miller").fetchAll(db) -} +let streisands = Person.filter(Col.lastName == "Streisand").fetchAll(dbQueue)