Skip to content

Commit f21ff7d

Browse files
author
Nathan Fallet
authored
Merge pull request #1142 from stephencelis/attach-detach
2 parents 642d4fa + 7868fdf commit f21ff7d

25 files changed

+597
-325
lines changed

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
0.13.3 (25-01-2022), [diff][diff-0.13.3]
1+
0.14.0 (tbd), [diff][diff-0.14.0]
2+
========================================
3+
4+
* Support `ATTACH`/`DETACH` ([#30][], [#1142][])
5+
* Support `WITH` clause ([#1139][])
6+
* Add `Value` conformance for `NSURL` ([#1110][], [#1141][])
7+
* Add decoding for `UUID` ([#1137][])
8+
* Fix `insertMany([Encodable])` ([#1130][], [#1138][])
9+
* Fix incorrect spelling of `remove_diacritics` ([#1128][])
10+
* Fix project build order ([#1131][])
11+
* Performance improvements ([#1109][], [#1115][], [#1132][])
12+
13+
0.13.3 (27-03-2022), [diff][diff-0.13.3]
214
========================================
315

416
* UUID Fix ([#1112][])
@@ -110,7 +122,9 @@
110122
[diff-0.13.1]: https://github.com/stephencelis/SQLite.swift/compare/0.13.0...0.13.1
111123
[diff-0.13.2]: https://github.com/stephencelis/SQLite.swift/compare/0.13.1...0.13.2
112124
[diff-0.13.3]: https://github.com/stephencelis/SQLite.swift/compare/0.13.2...0.13.3
125+
[diff-0.14.0]: https://github.com/stephencelis/SQLite.swift/compare/0.13.3...0.14.0
113126

127+
[#30]: https://github.com/stephencelis/SQLite.swift/issues/30
114128
[#142]: https://github.com/stephencelis/SQLite.swift/issues/142
115129
[#315]: https://github.com/stephencelis/SQLite.swift/issues/315
116130
[#426]: https://github.com/stephencelis/SQLite.swift/pull/426
@@ -150,6 +164,18 @@
150164
[#1095]: https://github.com/stephencelis/SQLite.swift/pull/1095
151165
[#1100]: https://github.com/stephencelis/SQLite.swift/pull/1100
152166
[#1105]: https://github.com/stephencelis/SQLite.swift/pull/1105
167+
[#1109]: https://github.com/stephencelis/SQLite.swift/issues/1109
168+
[#1110]: https://github.com/stephencelis/SQLite.swift/pull/1110
153169
[#1112]: https://github.com/stephencelis/SQLite.swift/pull/1112
170+
[#1115]: https://github.com/stephencelis/SQLite.swift/pull/1115
154171
[#1119]: https://github.com/stephencelis/SQLite.swift/pull/1119
155172
[#1121]: https://github.com/stephencelis/SQLite.swift/pull/1121
173+
[#1128]: https://github.com/stephencelis/SQLite.swift/issues/1128
174+
[#1130]: https://github.com/stephencelis/SQLite.swift/issues/1130
175+
[#1131]: https://github.com/stephencelis/SQLite.swift/pull/1131
176+
[#1132]: https://github.com/stephencelis/SQLite.swift/pull/1132
177+
[#1137]: https://github.com/stephencelis/SQLite.swift/pull/1137
178+
[#1138]: https://github.com/stephencelis/SQLite.swift/pull/1138
179+
[#1139]: https://github.com/stephencelis/SQLite.swift/pull/1139
180+
[#1141]: https://github.com/stephencelis/SQLite.swift/pull/1141
181+
[#1142]: https://github.com/stephencelis/SQLite.swift/pull/1142

Documentation/Index.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Read-Write Databases](#read-write-databases)
1111
- [Read-Only Databases](#read-only-databases)
1212
- [In-Memory Databases](#in-memory-databases)
13+
- [URI parameters](#uri-parameters)
1314
- [Thread-Safety](#thread-safety)
1415
- [Building Type-Safe SQL](#building-type-safe-sql)
1516
- [Expressions](#expressions)
@@ -61,9 +62,9 @@
6162
- [Custom Collations](#custom-collations)
6263
- [Full-text Search](#full-text-search)
6364
- [Executing Arbitrary SQL](#executing-arbitrary-sql)
65+
- [Attaching and detaching databases](#attaching-and-detaching-databases)
6466
- [Logging](#logging)
6567

66-
6768
[]: #sqliteswift-documentation
6869

6970

@@ -334,6 +335,16 @@ let db = try Connection(.temporary)
334335
In-memory databases are automatically deleted when the database connection is
335336
closed.
336337

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.
337348

338349
#### Thread-Safety
339350

@@ -372,6 +383,9 @@ to their [SQLite counterparts](https://www.sqlite.org/datatype3.html).
372383
| `String` | `TEXT` |
373384
| `nil` | `NULL` |
374385
| `SQLite.Blob`| `BLOB` |
386+
| `URL` | `TEXT` |
387+
| `UUID` | `TEXT` |
388+
| `Date` | `TEXT` |
375389

376390
> *While `Int64` is the basic, raw type (to preserve 64-bit integers on
377391
> 32-bit platforms), `Int` and `Bool` work transparently.
@@ -1089,8 +1103,8 @@ users.limit(5, offset: 5)
10891103

10901104
#### Recursive and Hierarchical Queries
10911105

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.
10941108

10951109
```swift
10961110
// Get the management chain for the manager with id == 8
@@ -2070,6 +2084,25 @@ let backup = try db.backup(usingConnection: target)
20702084
try backup.step()
20712085
```
20722086

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+
20732106
## Logging
20742107

20752108
We can log SQL using the database’s `trace` function.

Documentation/Planning.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ be referred to when it comes time to add the corresponding feature._
2121

2222
### Features
2323

24-
* encapsulate ATTACH DATABASE / DETACH DATABASE as methods, per
25-
[#30](https://github.com/stephencelis/SQLite.swift/issues/30)
2624
* provide separate threads for update vs read, so updates don't block reads,
2725
per [#236](https://github.com/stephencelis/SQLite.swift/issues/236)
2826
* expose triggers, per

Package.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ let package = Package(
4040
"Info.plist"
4141
],
4242
resources: [
43-
.copy("fixtures/encrypted-3.x.sqlite"),
44-
.copy("fixtures/encrypted-4.x.sqlite")
43+
.copy("Resources")
4544
]
4645
)
4746
]
@@ -55,10 +54,15 @@ package.targets = [
5554
dependencies: [.product(name: "CSQLite", package: "CSQLite")],
5655
exclude: ["Extensions/FTS4.swift", "Extensions/FTS5.swift"]
5756
),
58-
.testTarget(name: "SQLiteTests", dependencies: ["SQLite"], path: "Tests/SQLiteTests", exclude: [
59-
"FTSIntegrationTests.swift",
60-
"FTS4Tests.swift",
61-
"FTS5Tests.swift"
62-
])
57+
.testTarget(
58+
name: "SQLiteTests",
59+
dependencies: ["SQLite"],
60+
path: "Tests/SQLiteTests", exclude: [
61+
"FTSIntegrationTests.swift",
62+
"FTS4Tests.swift",
63+
"FTS5Tests.swift"
64+
],
65+
resources: [ .copy("Resources") ]
66+
)
6367
]
6468
#endif

SQLite.swift.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Pod::Spec.new do |s|
3535
ss.library = 'sqlite3'
3636

3737
ss.test_spec 'tests' do |test_spec|
38-
test_spec.resources = 'Tests/SQLiteTests/fixtures/*'
38+
test_spec.resources = 'Tests/SQLiteTests/Resources/*'
3939
test_spec.source_files = 'Tests/SQLiteTests/*.swift'
4040
test_spec.ios.deployment_target = ios_deployment_target
4141
test_spec.tvos.deployment_target = tvos_deployment_target
@@ -55,7 +55,7 @@ Pod::Spec.new do |s|
5555
ss.dependency 'sqlite3'
5656

5757
ss.test_spec 'tests' do |test_spec|
58-
test_spec.resources = 'Tests/SQLiteTests/fixtures/*'
58+
test_spec.resources = 'Tests/SQLiteTests/Resources/*'
5959
test_spec.source_files = 'Tests/SQLiteTests/*.swift'
6060
test_spec.ios.deployment_target = ios_deployment_target
6161
test_spec.tvos.deployment_target = tvos_deployment_target
@@ -73,7 +73,7 @@ Pod::Spec.new do |s|
7373
ss.dependency 'SQLCipher', '>= 4.0.0'
7474

7575
ss.test_spec 'tests' do |test_spec|
76-
test_spec.resources = 'Tests/SQLiteTests/fixtures/*'
76+
test_spec.resources = 'Tests/SQLiteTests/Resources/*'
7777
test_spec.source_files = 'Tests/SQLiteTests/*.swift'
7878
test_spec.ios.deployment_target = ios_deployment_target
7979
test_spec.tvos.deployment_target = tvos_deployment_target

0 commit comments

Comments
 (0)