From c3105fa66f78079d351b5b7220ea2a322031352d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 20 Jul 2016 14:00:25 +0200 Subject: [PATCH] Documentation --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67cca36f2..7df602d5e 100644 --- a/README.md +++ b/README.md @@ -1584,6 +1584,8 @@ Add the [TableMapping](#tablemapping-protocol) protocol and you can stop writing ```swift let persons = Person.filter(emailColumn != nil).order(nameColumn).fetchAll(db) let person = Person.fetchOne(db, key: 1) +let person = Person.fetchOne(db, key: ["email": "arthur@example.com"]) +let countries = Country.fetchAll(db, keys: ["FR", "US"]) ``` To learn more about querying records, check the [query interface](#the-query-interface). @@ -1625,7 +1627,15 @@ let person = Person.fetchOne(db, key: 1)! try person.delete(db) ``` -For batch deletions, you have to execute an [SQL query](#executing-updates): +The [TableMapping](#tablemapping-protocol) protocol gives you methods that delete according to primary key or any unique index: + +```swift +try Person.deleteOne(db, key: 1) +try Person.deleteOne(db, key: ["email": "arthur@example.com"]) +try Country.deleteAll(db, keys: ["FR", "US"]) +``` + +Other deletions require an [SQL query](#executing-updates): ```swift try db.execute("DELETE FROM persons") @@ -1637,7 +1647,7 @@ try db.execute("DELETE FROM persons") [Record](#record-class) subclasses and types that adopt the [TableMapping](#tablemapping-protocol) protocol can be counted: ```swift -let personWithEmailCount = Person.filter(email != nil).fetchCount(db) // Int +let personWithEmailCount = Person.filter(emailColumn != nil).fetchCount(db) // Int ```