You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: GRDB/Documentation.docc/Concurrency.md
-47Lines changed: 0 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -334,53 +334,6 @@ In the illustration below, the striped band shows the delay needed for the readi
334
334
335
335
Types that conform to ``TransactionObserver`` can also use those methods in their ``TransactionObserver/databaseDidCommit(_:)`` method, in order to process database changes without blocking other threads that want to write into the database.
336
336
337
-
## Database Snapshots
338
-
339
-
**``DatabasePool`` can take snapshots.** A database snapshot sees an unchanging database content, as it existed at the moment it was created.
340
-
341
-
"Unchanging" means that a snapshot never sees any database modifications during all its lifetime. And yet it doesn't prevent database updates. This "magic"is made possible by SQLite's WAL mode (see [Isolation In SQLite](https://sqlite.org/isolation.html)).
342
-
343
-
```swift
344
-
let snapshot =try dbPool.makeSnapshot()
345
-
```
346
-
347
-
You can create as many snapshots as you need, regardless of the maximum number of readers defined by the ``Configuration/maximumReaderCount`` configuration. A snapshot connection is closed when the snapshot is deallocated.
348
-
349
-
**A snapshot can be used from any thread.** It has the same database access methods as database queues and pools, defined by the ``DatabaseReader`` protocol:
350
-
351
-
```swift
352
-
let playerCount =try snapshot.read { db in
353
-
try Player.fetchCount(db)
354
-
}
355
-
```
356
-
357
-
When you want to control the latest committed changes seen by a snapshot, create the snapshot from within a write, outside ofany transaction:
358
-
359
-
```swift
360
-
let snapshot1 =try dbPool.writeWithoutTransaction { db -> DatabaseSnapshot in
361
-
try db.inTransaction {
362
-
// delete all players
363
-
try Player.deleteAll()
364
-
return .commit
365
-
}
366
-
367
-
// <- not in a transaction here
368
-
return dbPool.makeSnapshot()
369
-
}
370
-
// <- Other threads may modify the database here
371
-
let snapshot2 =try dbPool.makeSnapshot()
372
-
373
-
try snapshot1.read { db in
374
-
// Guaranteed to be zero
375
-
try Player.fetchCount(db)
376
-
}
377
-
378
-
try snapshot2.read { db in
379
-
// Could be anything
380
-
try Player.fetchCount(db)
381
-
}
382
-
```
383
-
384
337
## Topics
385
338
386
339
### Database Connections with Concurrency Guarantees
0 commit comments