mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Change default transaction kind to deferred (the SQLite default).
This commit is contained in:
1 parent
a913aba018
commit
e24cb1783c
3 files changed
+8
-7
No files matched your search
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user