mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
It looks like documentation wants that DatabaseQueue automatically opens transactions as well...
This commit is contained in:
1 parent
1275ebc2b1
commit
02927106ca
1 file changed
+10
-60
@@ -1275,7 +1275,16 @@ Grape.fromDatabaseValue(row[0]) // nil
|
||||
|
||||
**Transactions** are a fundamental concept of SQLite that guarantee [data consistency](https://www.sqlite.org/transactional.html) as well as [proper isolation](https://sqlite.org/isolation.html) between application threads and database connections.
|
||||
|
||||
These are all important words for a database expert, but not all developers know them very well. That's why GRDB will sometimes open transactions for you, automatically, as a way to enforce its [concurrency guarantees](#concurrency), and provide maximal security for both your application data and application logic. See the [list of database access methods](#list-of-database-access-methods) for an overview.
|
||||
These are all important words for a database expert, but not all developers know them very well. That's why GRDB will generally open transactions for you, automatically, as a way to enforce its [concurrency guarantees](#concurrency), and provide maximal security for both your application data and application logic:
|
||||
|
||||
```swift
|
||||
// BEGIN TRANSACTION
|
||||
// INSERT INTO players ...
|
||||
// COMMIT
|
||||
try dbPool.write { db in
|
||||
try Player(...).insert(db)
|
||||
}
|
||||
```
|
||||
|
||||
**Yet some users need to control exactly when transactions take place.** This is an advanced use case, described below.
|
||||
|
||||
@@ -6224,7 +6233,6 @@ You can catch those errors and wait for [UIApplicationDelegate.applicationProtec
|
||||
- [DatabaseWriter and DatabaseReader Protocols](#databasewriter-and-databasereader-protocols)
|
||||
- [Unsafe Concurrency APIs](#unsafe-concurrency-apis)
|
||||
- [Dealing with External Connections](#dealing-with-external-connections)
|
||||
- [List of Database Access Methods](#list-of-database-access-methods)
|
||||
|
||||
|
||||
### Guarantees and Rules
|
||||
@@ -6596,64 +6604,6 @@ If you absolutely need multiple connections, then:
|
||||
- [Ask questions](https://github.com/groue/GRDB.swift/issues)
|
||||
|
||||
|
||||
### List of Database Access Methods
|
||||
|
||||
This is the list of database access methods:
|
||||
|
||||
- [DatabaseQueue](#databasequeue-methods)
|
||||
- [DatabasePool](#databasepool-methods)
|
||||
- [DatabaseSnapshot](#databasesnapshot-methods)
|
||||
- [DatabaseReader Protocol](#databasereader-protocol-methods)
|
||||
- [DatabaseWriter Protocol](#databasewriter-protocol-methods)
|
||||
|
||||
|
||||
#### [DatabaseQueue](#database-queues) Methods
|
||||
|
||||
| Method | Opens a Transaction | Notes |
|
||||
| ------ | ------------------- | ----- |
|
||||
| `read` | NO | Guaranteed read-only access from SQLite 3.8.0 (iOS 8.2+, macOS 10.10+). |
|
||||
| `inDatabase` | NO | |
|
||||
| `inTransaction` | YES | |
|
||||
|
||||
|
||||
#### [DatabasePool](#database-pools) Methods
|
||||
|
||||
| Method | Opens a Transaction | Notes |
|
||||
| ------ | ------------------- | ----- |
|
||||
| `write` | YES | |
|
||||
| `writeInTransaction` | YES | |
|
||||
| `writeWithoutTransaction` | NO | |
|
||||
| `read` | YES | |
|
||||
| `readFromCurrentState` | YES | Must be executed from a writing block. Can't be executed from inside a transaction. |
|
||||
| `makeSnapshot` | YES | Can't be executed from inside a transaction. |
|
||||
|
||||
|
||||
#### [DatabaseSnapshot](#database-snapshots) Methods
|
||||
|
||||
| Method | Opens a Transaction | Notes |
|
||||
| ------ | ------------------- | ----- |
|
||||
| `read` | YES | |
|
||||
|
||||
|
||||
#### [DatabaseReader Protocol](http://groue.github.io/GRDB.swift/docs/2.10/Protocols/DatabaseReader.html) Methods
|
||||
|
||||
| Method | Notes |
|
||||
| ------ | ----- |
|
||||
| `read` | |
|
||||
| `unsafeRead` | |
|
||||
| `unsafeReentrantRead` | |
|
||||
|
||||
|
||||
#### [DatabaseWriter Protocol](http://groue.github.io/GRDB.swift/docs/2.10/Protocols/DatabaseWriter.html) Methods
|
||||
|
||||
| Method | Notes |
|
||||
| ------ | ----- |
|
||||
| `write` | |
|
||||
| `writeWithoutTransaction` | |
|
||||
| `unsafeReentrantWrite` | |
|
||||
| `readFromCurrentState` | Must be executed from a writing block. Can't be executed from inside a transaction. |
|
||||
|
||||
|
||||
## Performance
|
||||
|
||||
GRDB is a reasonably fast library, and can deliver quite efficient SQLite access. See [Comparing the Performances of Swift SQLite libraries](https://github.com/groue/GRDB.swift/wiki/Performance) for an overview.
|
||||
|
||||
Reference in new issue
Block a user