From 75728418af8a040e52c96203bb2b0edd2159c5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 1 Jun 2016 09:28:57 +0200 Subject: [PATCH] More savepoints documentation --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aff356b93..04978f588 100644 --- a/README.md +++ b/README.md @@ -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 ... + } } ```