Add links to DocC reference

This commit is contained in:
Gwendal Roué committed 2023-03-12 16:32:54 +01:00
1 parent 93616775f6
commit ff7f9073fc
1 file changed
+23 -8
+23 -8
View File
@@ -322,7 +322,7 @@ Documentation
#### Reference
- [GRDB Reference](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/)
- 📖 [GRDB Reference](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/)
#### Getting Started
@@ -477,7 +477,7 @@ Advanced topics:
## Executing Updates
Once granted with a [database connection], the `execute` method executes the SQL statements that do not return any database row, such as `CREATE TABLE`, `INSERT`, `DELETE`, `ALTER`, etc.
Once granted with a [database connection], the [`execute(sql:arguments:)`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/database/execute(sql:arguments:)) method executes the SQL statements that do not return any database row, such as `CREATE TABLE`, `INSERT`, `DELETE`, `ALTER`, etc.
For example:
@@ -503,12 +503,14 @@ try dbQueue.write { db in
The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [`StatementArguments`] for a detailed documentation of SQLite arguments.
You can also embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details.
You can also embed query arguments right into your SQL queries, with [`execute(literal:)`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/database/execute(literal:)), as in the example below. See [SQL Interpolation] for more details.
```swift
try dbQueue.write { db in
let name = "O'Brien"
let score = 550
try db.execute(literal: """
INSERT INTO player (name, score) VALUES (\("O'Brien"), \(550))
INSERT INTO player (name, score) VALUES (\(name), \(score))
""")
}
```
@@ -553,7 +555,7 @@ try db.execute(literal: """
When you want to make sure that a single statement is executed, use a prepared [`Statement`].
**After an INSERT statement**, you can get the row ID of the inserted row:
**After an INSERT statement**, you can get the row ID of the inserted row with [`lastInsertedRowID`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/database/lastinsertedrowid):
```swift
try db.execute(
@@ -653,6 +655,8 @@ try Row.fetchOne(...) // Row?
### Cursors
📖 [`Cursor`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/cursor)
**Whenever you consume several rows from the database, you can fetch an Array, a Set, or a Cursor**.
The `fetchAll()` and `fetchSet()` methods return regular Swift array and sets, that you iterate like all other arrays and sets:
@@ -778,6 +782,7 @@ If you don't see, or don't care about the difference, use arrays. If you care ab
- [Column Values](#column-values)
- [DatabaseValue](#databasevalue)
- [Rows as Dictionaries](#rows-as-dictionaries)
- 📖 [`Row`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/row)
#### Fetching Rows
@@ -945,9 +950,11 @@ Generally speaking, you can extract the type you need, provided it can be conver
#### DatabaseValue
**DatabaseValue is an intermediate type between SQLite and your values, which gives information about the raw value stored in the database.**
📖 [`DatabaseValue`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasevalue)
You get DatabaseValue just like other value types:
**`DatabaseValue` is an intermediate type between SQLite and your values, which gives information about the raw value stored in the database.**
You get `DatabaseValue` just like other value types:
```swift
let dbValue: DatabaseValue = row[0]
@@ -969,7 +976,7 @@ case .blob(let data): print("Data: \(data)")
}
```
You can extract regular [values](#values) (Bool, Int, String, Date, Swift enums, etc.) from DatabaseValue with the [DatabaseValueConvertible.fromDatabaseValue()](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasevalueconvertible/fromdatabasevalue(_:)-21zzv) method:
You can extract regular [values](#values) (Bool, Int, String, Date, Swift enums, etc.) from `DatabaseValue` with the [fromDatabaseValue()](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasevalueconvertible/fromdatabasevalue(_:)-21zzv) method:
```swift
let dbValue: DatabaseValue = row["bookCount"]
@@ -1055,6 +1062,8 @@ See the documentation of [`Dictionary.init(_:uniquingKeysWith:)`](https://develo
### Value Queries
📖 [`DatabaseValueConvertible`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasevalueconvertible)
**Instead of rows, you can directly fetch values.** There are many supported [value types](#values) (Bool, Int, String, Date, Swift enums, etc.).
Like rows, fetch values as **cursors**, **arrays**, **sets**, or **single** values (see [fetching methods](#fetching-methods)). Values are extracted from the leftmost column of the SQL queries:
@@ -1450,6 +1459,8 @@ SELECT maxLength(name) FROM player; -- custom aggregate
### Custom SQL Functions
📖 [`DatabaseFunction`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasefunction)
A *function* argument takes an array of [DatabaseValue](#databasevalue), and returns any valid [value](#values) (Bool, Int, String, Date, Swift enums, etc.) The number of database values is guaranteed to be *argumentCount*.
SQLite has the opportunity to perform additional optimizations when functions are "pure", which means that their result only depends on their arguments. So make sure to set the *pure* argument to true when possible.
@@ -1529,6 +1540,8 @@ Player.select(reverseString(nameColumn))
### Custom Aggregates
📖 [`DatabaseFunction`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databasefunction), [`DatabaseAggregate`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databaseaggregate)
Before registering a custom aggregate, you need to define a type that adopts the `DatabaseAggregate` protocol:
```swift
@@ -1637,6 +1650,8 @@ Database.isSQLiteInternalTable(...)
Database.isGRDBInternalTable(...)
```
For more information, see [`tableExists(_:)`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/database/tableexists(_:)) and related methods.
## Row Adapters