WIP: GRDB2MigrationGuide.md

This commit is contained in:
Gwendal Roué committed 2018-05-02 21:55:53 +02:00
1 parent 0aa75f418f
commit c7a1daa8e5
1 file changed
+30 -1
+30 -1
View File
@@ -240,6 +240,33 @@ Now `write` automatically wraps your changes in a transaction, with the guarante
## If You Use Database Snapshots
With GRDB 2, you used to create [database snapshots] with the `makeSnaphot` [DatabasePool] method. For example:
```swift
// GRDB 2
let snapshot: DatabaseSnapshot = try dbPool.write { db in
try Player.deleteAll()
return dbPool.makeSnapshot()
}
// Guaranteed to be zero
let count = try snapshot.read { db in
try Player.fetchCount(db)
}
```
GRDB 3 will crash the above code on the `makeSnapshot()` line, with a fatal error: "makeSnapshot() must not be called from inside a transaction."
To avoid this error, you will need [precise transaction handling]:
```swift
// GRDB 3
let snapshot: DatabaseSnapshot = try dbPool.writeWithoutTransaction { db in
try Player.deleteAll()
return dbPool.makeSnapshot()
}
```
## If You Use RxGRDB
@@ -257,6 +284,8 @@ Now `write` automatically wraps your changes in a transaction, with the guarante
[DatabaseMigrator]: ../README.md#migrations
[database observation tools]: ../README.md#database-changes-observation
[Transactions and Savepoints]: ../README.md#transactions-and-savepoints
[precise transaction handling]: ../README.md#transactions-and-savepoints
[DatabaseQueue]: ../README.md#database-queues
[DatabasePool]: ../README.md#database-pools
[FMDB]: http://github.com/ccgus/fmdb
[database snapshots]: ../README.md#database-snapshots
[FMDB]: http://github.com/ccgus/fmdb