|
10 | 10 | - [Read-Write Databases](#read-write-databases) |
11 | 11 | - [Read-Only Databases](#read-only-databases) |
12 | 12 | - [In-Memory Databases](#in-memory-databases) |
| 13 | + - [URI parameters](#uri-parameters) |
13 | 14 | - [Thread-Safety](#thread-safety) |
14 | 15 | - [Building Type-Safe SQL](#building-type-safe-sql) |
15 | 16 | - [Expressions](#expressions) |
|
61 | 62 | - [Custom Collations](#custom-collations) |
62 | 63 | - [Full-text Search](#full-text-search) |
63 | 64 | - [Executing Arbitrary SQL](#executing-arbitrary-sql) |
| 65 | + - [Attaching and detaching databases](#attaching-and-detaching-databases) |
64 | 66 | - [Logging](#logging) |
65 | 67 |
|
66 | | - |
67 | 68 | [↩]: #sqliteswift-documentation |
68 | 69 |
|
69 | 70 |
|
@@ -334,6 +335,16 @@ let db = try Connection(.temporary) |
334 | 335 | In-memory databases are automatically deleted when the database connection is |
335 | 336 | closed. |
336 | 337 |
|
| 338 | +#### URI parameters |
| 339 | + |
| 340 | +We can pass `.uri` to the `Connection` initializer to control more aspects of |
| 341 | +the database connection with the help of `URIQueryParameter`s: |
| 342 | + |
| 343 | +```swift |
| 344 | +let db = try Connection(.uri("file.sqlite", parameters: [.cache(.private), .noLock(true)])) |
| 345 | +``` |
| 346 | + |
| 347 | +See [Uniform Resource Identifiers](https://www.sqlite.org/uri.html#recognized_query_parameters) for more details. |
337 | 348 |
|
338 | 349 | #### Thread-Safety |
339 | 350 |
|
@@ -372,6 +383,9 @@ to their [SQLite counterparts](https://www.sqlite.org/datatype3.html). |
372 | 383 | | `String` | `TEXT` | |
373 | 384 | | `nil` | `NULL` | |
374 | 385 | | `SQLite.Blob`† | `BLOB` | |
| 386 | +| `URL` | `TEXT` | |
| 387 | +| `UUID` | `TEXT` | |
| 388 | +| `Date` | `TEXT` | |
375 | 389 |
|
376 | 390 | > *While `Int64` is the basic, raw type (to preserve 64-bit integers on |
377 | 391 | > 32-bit platforms), `Int` and `Bool` work transparently. |
@@ -1089,8 +1103,8 @@ users.limit(5, offset: 5) |
1089 | 1103 |
|
1090 | 1104 | #### Recursive and Hierarchical Queries |
1091 | 1105 |
|
1092 | | -We can perform a recursive or hierarchical query using a [query's](#queries) `with` |
1093 | | -function. |
| 1106 | +We can perform a recursive or hierarchical query using a [query's](#queries) |
| 1107 | +[`WITH`](https://sqlite.org/lang_with.html) function. |
1094 | 1108 |
|
1095 | 1109 | ```swift |
1096 | 1110 | // Get the management chain for the manager with id == 8 |
@@ -2070,6 +2084,25 @@ let backup = try db.backup(usingConnection: target) |
2070 | 2084 | try backup.step() |
2071 | 2085 | ``` |
2072 | 2086 |
|
| 2087 | +## Attaching and detaching databases |
| 2088 | + |
| 2089 | +We can [ATTACH](https://www3.sqlite.org/lang_attach.html) and [DETACH](https://www3.sqlite.org/lang_detach.html) |
| 2090 | +databases to an existing connection: |
| 2091 | + |
| 2092 | +```swift |
| 2093 | +let db = try Connection("db.sqlite") |
| 2094 | + |
| 2095 | +try db.attach(.uri("external.sqlite", parameters: [.mode(.readOnly)]), as: "external") |
| 2096 | +// ATTACH DATABASE 'file:external.sqlite?mode=ro' AS 'external' |
| 2097 | + |
| 2098 | +let table = Table("table", database: "external") |
| 2099 | +let count = try db.scalar(table.count) |
| 2100 | +// SELECT count(*) FROM 'external.table' |
| 2101 | + |
| 2102 | +try db.detach("external") |
| 2103 | +// DETACH DATABASE 'external' |
| 2104 | +``` |
| 2105 | + |
2073 | 2106 | ## Logging |
2074 | 2107 |
|
2075 | 2108 | We can log SQL using the database’s `trace` function. |
|
0 commit comments