Update "Differences between Database Queues and Pools" chapter

This commit is contained in:
Gwendal Roué committed 2018-08-25 14:17:46 +02:00
1 parent 4572e493e6
commit 4fcc1f81d5
1 file changed
+2 -29
+2 -29
View File
@@ -7051,36 +7051,9 @@ Despite the common [guarantees and rules](#guarantees-and-rules) shared by [data
![DatabasePoolScheduling](https://cdn.rawgit.com/groue/GRDB.swift/development/Documentation/Images/DatabasePoolScheduling.svg)
See how, with database pools, two threads can see different database states at the same time.
See how, with database pools, two reads can see different database states at the same time.
This may sound scary. But don't freak out:
First of all, you can use the database as the *single source of truth* with the `write` database access method, which always grants exclusive access to the database file:
```swift
try dbQueue.write { db in // or dbPool.write
// exclusive access to the database file
}
```
And you can alleviate the consequences of obsolete data with [database observation](#database-changes-observation), which automatically notifies of database changes. For example, with RxGRDB:
```swift
// Observe Player of id 1:
Player.filter(key: 1).rx
.fetchAll(in: dbQueue) // or fetchAll(in: dbPool)
.subscribe(onNext: { player: Player? in
// Player has changed: update the view.
updateView(with: player)
// While we're updating the view on the main thread, other
// threads can modify the database. But when this happens,
// this closure is guaranteed to be called again, with a
// refreshed player.
})
```
For more information about database pools, grab information about SQLite [WAL mode](https://www.sqlite.org/wal.html) and [snapshot isolation](https://sqlite.org/isolation.html).
For more information about database pools, grab information about SQLite [WAL mode](https://www.sqlite.org/wal.html) and [snapshot isolation](https://sqlite.org/isolation.html). See [Database Observation](#database-changes-observation) when you look after automatic notifications of database changes.
### Advanced DatabasePool