mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Documentation
This commit is contained in:
1 parent
8b09b2cdba
commit
c3105fa66f
1 file changed
+12
-2
@@ -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
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user