Change default transaction kind to deferred (the SQLite default).

This commit is contained in:
Gwendal Roué authored and Gwendal Roué committed 2017-06-20 07:54:19 +02:00
1 parent a913aba018
commit e24cb1783c
3 files changed
+8 -7

No files matched your search

+2 -2
View File
@@ -39,8 +39,8 @@ public struct Configuration {
/// The default kind of transaction.
///
/// Default: Immediate
public var defaultTransactionKind: Database.TransactionKind = .immediate
/// Default: deferred
public var defaultTransactionKind: Database.TransactionKind = .deferred
// MARK: - Concurrency
+5 -5
View File
@@ -1272,20 +1272,20 @@ SQLite savepoints are more than nested transactions, though. For advanced savepo
### Transaction Kinds
SQLite supports [three kinds of transactions](https://www.sqlite.org/lang_transaction.html): deferred, immediate, and exclusive. GRDB defaults to immediate.
SQLite supports [three kinds of transactions](https://www.sqlite.org/lang_transaction.html): deferred (the default), immediate, and exclusive.
The transaction kind can be changed in the database configuration, or for each transaction:
```swift
// A connection with default DEFERRED transactions:
// Set the default transaction kind to IMMEDIATE:
var config = Configuration()
config.defaultTransactionKind = .deferred
config.defaultTransactionKind = .immediate
let dbQueue = try DatabaseQueue(path: "...", configuration: config)
// Opens a DEFERRED transaction:
// BEGIN IMMEDIATE TRANSACTION ...
dbQueue.inTransaction { db in ... }
// Opens an EXCLUSIVE transaction:
// BEGIN EXCLUSIVE TRANSACTION ...
dbQueue.inTransaction(.exclusive) { db in ... }
```
@@ -387,6 +387,7 @@ class DatabaseSavepointTests: GRDBTestCase {
}
func testNestedSavepointFromDatabaseWithDefaultImmediateTransactions() throws {
dbConfiguration.defaultTransactionKind = .immediate
let dbQueue = try makeDatabaseQueue()
let observer = Observer()
dbQueue.add(transactionObserver: observer)