Skip to content

Commit 71880a9

Browse files
committed
Enhance Documentation
1 parent 14fb194 commit 71880a9

17 files changed

+151
-56
lines changed

GRDB/Core/Configuration.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import Dispatch
22
import Foundation
33

4-
/// The configuration of a ``Database``, ``DatabaseQueue``, or ``DatabasePool``.
4+
/// The configuration of a database connection.
55
///
6-
/// Usage:
6+
/// You create a `Configuration` before opening a database connection:
77
///
88
/// ```swift
99
/// var config = Configuration()
1010
/// config.readonly = true
11-
/// config.foreignKeysEnabled = true // Default is already true
12-
/// config.label = "MyDatabase" // Useful when your app opens multiple databases
13-
/// config.maximumReaderCount = 10 // (DatabasePool only) The default is 5
11+
/// config.maximumReaderCount = 2 // (DatabasePool only) The default is 5
12+
/// config.prepareDatabase { db in // A function to run on connection
13+
/// db.trace { print("SQL >", $0) }
14+
/// }
1415
///
1516
/// let dbQueue = try DatabaseQueue( // or DatabasePool
1617
/// path: "/path/to/database.sqlite",
1718
/// configuration: config)
1819
/// ```
20+
///
21+
/// See <doc:DatabaseConnections>.
1922
public struct Configuration {
2023

2124
// MARK: - Misc options

GRDB/Core/Database.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_
1010

1111
/// An SQLite connection.
1212
///
13-
/// You don't create `Database` instances directly. Instead, you use a database
14-
/// access method from ``DatabaseQueue``, ``DatabasePool``.
15-
/// ``DatabaseSnapshot``, ``DatabaseMigrator`` or ``ValueObservation``.
16-
/// For example:
13+
/// You don't create `Database` instances directly. Instead, you connect to a
14+
/// database with one of the <doc:DatabaseConnections>, and you use a database
15+
/// access method. For example:
1716
///
1817
/// ```swift
1918
/// let dbQueue = try DatabaseQueue()
2019
///
21-
/// // The Database is the `db` in the closure:
22-
/// try dbQueue.write { db in
20+
/// try dbQueue.write { (db: Database) in
2321
/// try Player(name: "Arthur").insert(db)
2422
/// }
2523
/// ```
@@ -71,7 +69,6 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_
7169
/// - ``add(transactionObserver:extent:)``
7270
/// - ``afterNextTransaction(onCommit:onRollback:)``
7371
/// - ``remove(transactionObserver:)``
74-
/// - ``TransactionObserver``
7572
/// - ``TransactionObservationExtent``
7673
///
7774
/// ### Collations

GRDB/Core/DatabasePool.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import UIKit
3131
///
3232
/// ### Accessing the Database
3333
///
34+
/// See ``DatabaseReader`` and ``DatabaseWriter`` for more database
35+
/// access methods.
36+
///
3437
/// - ``asyncConcurrentRead(_:)``
3538
/// - ``writeInTransaction(_:_:)``
3639
///

GRDB/Core/DatabaseQueue.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import UIKit
2222
///
2323
/// ### Accessing the Database
2424
///
25+
/// See ``DatabaseReader`` and ``DatabaseWriter`` for more database
26+
/// access methods.
27+
///
2528
/// - ``inDatabase(_:)``
2629
/// - ``inTransaction(_:_:)``
2730
///

GRDB/Core/DatabaseReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Combine
33
#endif
44
import Dispatch
55

6-
/// The protocol for types that read from an SQLite database.
6+
/// A type that reads from an SQLite database.
77
///
88
/// Do not declare new conformances to `DatabaseReader`. Only the
99
/// ``DatabaseQueue``, ``DatabasePool``, and ``DatabaseSnapshot`` types are

GRDB/Core/DatabaseWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Combine
33
#endif
44
import Dispatch
55

6-
/// The protocol for types that write into an SQLite database.
6+
/// A type that write into an SQLite database.
77
///
88
/// Do not declare new conformances to `DatabaseWriter`. Only the
99
/// ``DatabaseQueue`` and ``DatabasePool`` types are valid conforming types.

GRDB/Core/SQLRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
///
1717
/// try dbQueue.read { db in
1818
/// let players = try Player.filter(name: "O'Brien").fetchAll(db) // [Player]
19-
/// let maxScore = Player.maximumScore().fetchOne(db) // Int?
19+
/// let maxScore = try Player.maximumScore().fetchOne(db) // Int?
2020
/// }
2121
/// ```
2222
///

GRDB/Core/Statement.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ extension Statement {
515515
/// try dbQueue.read { db in
516516
/// // A cursor of database rows,
517517
/// // built from a prepared statement
518-
/// let statement = db.makeStatement(sql: "SELECT * FROM player")
518+
/// let statement = try db.makeStatement(sql: "SELECT * FROM player")
519519
/// let rows = try Row.fetchCursor(statement)
520520
/// while let row = try rows.next() {
521521
/// let id: Int64 = row["id"]
@@ -603,15 +603,17 @@ extension DatabaseCursor {
603603
}
604604

605605
/// A cursor that iterates a database statement without producing any value.
606-
/// Each call to the next() cursor method calls the sqlite3_step() C function.
606+
/// Each call to the `next()` method calls the `sqlite3_step()` C function.
607607
///
608608
/// For example:
609609
///
610-
/// try dbQueue.read { db in
611-
/// let statement = db.makeStatement(sql: "SELECT performSideEffect()")
612-
/// let cursor = statement.makeCursor()
613-
/// try cursor.next()
614-
/// }
610+
/// ```swift
611+
/// try dbQueue.read { db in
612+
/// let statement = try db.makeStatement(sql: "SELECT performSideEffect()")
613+
/// let cursor = statement.makeCursor()
614+
/// try cursor.next()
615+
/// }
616+
/// ```
615617
final class StatementCursor: DatabaseCursor {
616618
typealias Element = Void
617619
let _statement: Statement

GRDB/Core/TransactionObserver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ class DatabaseObservationBroker {
723723
///
724724
/// An observer starts receiving change notifications after it has been added to
725725
/// a database connection with the
726-
/// ``DatabaseWriter/add(transactionObserver:extent:)`` or
727-
/// ``Database/add(transactionObserver:extent:)`` methods.
726+
/// ``DatabaseWriter/add(transactionObserver:extent:)`` `DatabaseWriter` method,
727+
/// or the ``Database/add(transactionObserver:extent:)`` `Database` method.
728728
///
729729
/// All observer methods are called in a the writer dispatch queue, serialized
730730
/// with all database updates (see ``DatabaseWriter``).

GRDB/Documentation.docc/DatabaseConnections.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,41 @@
22

33
Open database connections to SQLite databases.
44

5+
## Overview
6+
7+
GRDB provides two classes for accessing SQLite databases: ``DatabaseQueue`` and ``DatabasePool``:
8+
9+
```swift
10+
import GRDB
11+
12+
// Pick one:
13+
let dbQueue = try DatabaseQueue(path: "/path/to/database.sqlite")
14+
let dbPool = try DatabasePool(path: "/path/to/database.sqlite")
15+
```
16+
17+
The differences are:
18+
19+
- `DatabasePool` allows concurrent database accesses (this can improve the performance of multithreaded applications).
20+
- `DatabasePool` opens your SQLite database in the [WAL mode](https://www.sqlite.org/wal.html) (unless read-only).
21+
- `DatabaseQueue` supports [in-memory databases](https://www.sqlite.org/inmemorydb.html).
22+
23+
**If you are not sure, choose `DatabaseQueue`.** You will always be able to switch to `DatabasePool` later.
24+
525
## Topics
626

7-
### Opening Database Connections
27+
### Configuring Database Connections
828

929
- ``Configuration``
10-
- ``DatabasePool``
30+
31+
### Opening Database Connections
32+
1133
- ``DatabaseQueue``
34+
- ``DatabasePool``
1235
- ``DatabaseSnapshot``
1336
- ``DatabaseReader``
1437
- ``DatabaseWriter``
1538

1639
### Using Database Connections
1740

1841
- ``Database``
42+
- ``DatabaseError``

0 commit comments

Comments
 (0)