mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
More savepoints documentation
This commit is contained in:
1 parent
df5a327da4
commit
75728418af
1 file changed
+13
-2
@@ -1071,9 +1071,20 @@ try dbQueue.inDatabase { db in // or dbPool.write { db in
|
||||
You can ask a database if a transaction is currently opened:
|
||||
|
||||
```swift
|
||||
func myCriticalMethod(db: Database) {
|
||||
func myCriticalMethod(db: Database) throws {
|
||||
precondition(db.isInsideTransaction, "This method requires a transaction")
|
||||
...
|
||||
try ...
|
||||
}
|
||||
```
|
||||
|
||||
Yet, you have a better option than checking for transactions: critical sections of your application should use savepoints, described below:
|
||||
|
||||
```swift
|
||||
func myCriticalMethod(db: Database) throws {
|
||||
try db.inSavepoint {
|
||||
// Here the database is guaranteed to be inside a transaction.
|
||||
try ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in new issue
Block a user