More savepoints documentation

This commit is contained in:
Gwendal Roué committed 2016-06-01 09:28:57 +02:00
1 parent df5a327da4
commit 75728418af
1 file changed
+13 -2
+13 -2
View File
@@ -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 ...
}
}
```