Skip to content

Commit c7154c6

Browse files
authored
Merge pull request stephencelis#1166 from stephencelis/docs
Doc updates 0.14.0
2 parents 884627c + ac09389 commit c7154c6

File tree

15 files changed

+153
-96
lines changed

15 files changed

+153
-96
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
0.14.0 (tbd), [diff][diff-0.14.0]
1+
0.14.0 (27-10-2022), [diff][diff-0.14.0]
22
========================================
3+
For breaking changes, see [Upgrading.md](Documentation/Upgrading.md).
34

45
* Support more complex schema changes and queries ([#1073][], [#1146][] [#1148][])
56
* Support `ATTACH`/`DETACH` ([#30][], [#1142][])
7+
* Expose connection flags (via `URIQueryParameter`) to open db ([#1074][]))
68
* Support `WITH` clause ([#1139][])
79
* Add `Value` conformance for `NSURL` ([#1110][], [#1141][])
810
* Add decoding for `UUID` ([#1137][])
@@ -164,6 +166,7 @@
164166
[#881]: https://github.com/stephencelis/SQLite.swift/pull/881
165167
[#919]: https://github.com/stephencelis/SQLite.swift/pull/919
166168
[#1073]: https://github.com/stephencelis/SQLite.swift/issues/1073
169+
[#1074]: https://github.com/stephencelis/SQLite.swift/issues/1074
167170
[#1075]: https://github.com/stephencelis/SQLite.swift/pull/1075
168171
[#1077]: https://github.com/stephencelis/SQLite.swift/issues/1077
169172
[#1094]: https://github.com/stephencelis/SQLite.swift/pull/1094

Documentation/Index.md

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Connecting to a Database](#connecting-to-a-database)
1010
- [Read-Write Databases](#read-write-databases)
1111
- [Read-Only Databases](#read-only-databases)
12+
- [In a Shared Group Container](#in-a-shared-group-container)
1213
- [In-Memory Databases](#in-memory-databases)
1314
- [URI parameters](#uri-parameters)
1415
- [Thread-Safety](#thread-safety)
@@ -41,14 +42,19 @@
4142
- [Updating Rows](#updating-rows)
4243
- [Deleting Rows](#deleting-rows)
4344
- [Transactions and Savepoints](#transactions-and-savepoints)
45+
- [Querying the Schema](#querying-the-schema)
4446
- [Altering the Schema](#altering-the-schema)
4547
- [Renaming Tables](#renaming-tables)
48+
- [Dropping Tables](#dropping-tables)
4649
- [Adding Columns](#adding-columns)
4750
- [Added Column Constraints](#added-column-constraints)
51+
- [Schema Changer](#schemachanger)
52+
- [Renaming Columns](#renaming-columns)
53+
- [Dropping Columns](#dropping-columns)
54+
- [Renaming/dropping Tables](#renamingdropping-tables)
4855
- [Indexes](#indexes)
4956
- [Creating Indexes](#creating-indexes)
5057
- [Dropping Indexes](#dropping-indexes)
51-
- [Dropping Tables](#dropping-tables)
5258
- [Migrations and Schema Versioning](#migrations-and-schema-versioning)
5359
- [Custom Types](#custom-types)
5460
- [Date-Time Values](#date-time-values)
@@ -83,7 +89,7 @@ process of downloading, compiling, and linking dependencies.
8389

8490
```swift
8591
dependencies: [
86-
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.13.3")
92+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.0")
8793
]
8894
```
8995

@@ -104,7 +110,7 @@ install SQLite.swift with Carthage:
104110
2. Update your Cartfile to include the following:
105111

106112
```ruby
107-
github "stephencelis/SQLite.swift" ~> 0.13.3
113+
github "stephencelis/SQLite.swift" ~> 0.14.0
108114
```
109115

110116
3. Run `carthage update` and [add the appropriate framework][Carthage Usage].
@@ -134,7 +140,7 @@ install SQLite.swift with Carthage:
134140
use_frameworks!
135141
136142
target 'YourAppTargetName' do
137-
pod 'SQLite.swift', '~> 0.13.3'
143+
pod 'SQLite.swift', '~> 0.14.0'
138144
end
139145
```
140146

@@ -148,7 +154,7 @@ with the OS you can require the `standalone` subspec:
148154

149155
```ruby
150156
target 'YourAppTargetName' do
151-
pod 'SQLite.swift/standalone', '~> 0.13.3'
157+
pod 'SQLite.swift/standalone', '~> 0.14.0'
152158
end
153159
```
154160

@@ -158,7 +164,7 @@ dependency to sqlite3 or one of its subspecs:
158164

159165
```ruby
160166
target 'YourAppTargetName' do
161-
pod 'SQLite.swift/standalone', '~> 0.13.3'
167+
pod 'SQLite.swift/standalone', '~> 0.14.0'
162168
pod 'sqlite3/fts5', '= 3.15.0' # SQLite 3.15.0 with FTS5 enabled
163169
end
164170
```
@@ -168,13 +174,13 @@ See the [sqlite3 podspec][sqlite3pod] for more details.
168174
#### Using SQLite.swift with SQLCipher
169175

170176
If you want to use [SQLCipher][] with SQLite.swift you can require the
171-
`SQLCipher` subspec in your Podfile:
177+
`SQLCipher` subspec in your Podfile (SPM is not supported yet, see [#1084](https://github.com/stephencelis/SQLite.swift/issues/1084)):
172178

173179
```ruby
174180
target 'YourAppTargetName' do
175181
# Make sure you only require the subspec, otherwise you app might link against
176182
# the system SQLite, which means the SQLCipher-specific methods won't work.
177-
pod 'SQLite.swift/SQLCipher', '~> 0.13.3'
183+
pod 'SQLite.swift/SQLCipher', '~> 0.14.0'
178184
end
179185
```
180186

@@ -325,6 +331,13 @@ let db = try Connection(path, readonly: true)
325331
> We welcome changes to the above sample code to show how to successfully copy and use a bundled "seed"
326332
> database for writing in an app.
327333

334+
#### In a shared group container
335+
336+
It is not recommend to store databases in a [shared group container],
337+
some users have reported crashes ([#1042](https://github.com/stephencelis/SQLite.swift/issues/1042)).
338+
339+
[shared group container]: https://developer.apple.com/documentation/foundation/filemanager/1412643-containerurl#
340+
328341
#### In-Memory Databases
329342

330343
If you omit the path, SQLite.swift will provision an [in-memory
@@ -1409,7 +1422,6 @@ for column in columns {
14091422
SQLite.swift comes with several functions (in addition to `Table.create`) for
14101423
altering a database schema in a type-safe manner.
14111424

1412-
14131425
### Renaming Tables
14141426

14151427
We can build an `ALTER TABLE RENAME TO` statement by calling the `rename`
@@ -1420,6 +1432,24 @@ try db.run(users.rename(Table("users_old")))
14201432
// ALTER TABLE "users" RENAME TO "users_old"
14211433
```
14221434

1435+
### Dropping Tables
1436+
1437+
We can build
1438+
[`DROP TABLE` statements](https://www.sqlite.org/lang_droptable.html)
1439+
by calling the `dropTable` function on a `SchemaType`.
1440+
1441+
```swift
1442+
try db.run(users.drop())
1443+
// DROP TABLE "users"
1444+
```
1445+
1446+
The `drop` function has one additional parameter, `ifExists`, which (when
1447+
`true`) adds an `IF EXISTS` clause to the statement.
1448+
1449+
```swift
1450+
try db.run(users.drop(ifExists: true))
1451+
// DROP TABLE IF EXISTS "users"
1452+
```
14231453

14241454
### Adding Columns
14251455

@@ -1484,57 +1514,54 @@ tables](#creating-a-table).
14841514
// ALTER TABLE "posts" ADD COLUMN "user_id" INTEGER REFERENCES "users" ("id")
14851515
```
14861516

1487-
### Renaming Columns
1517+
### SchemaChanger
1518+
1519+
Version 0.14.0 introduces `SchemaChanger`, an alternative API to perform more complex
1520+
migrations such as renaming columns. These operations work with all versions of
1521+
SQLite but use SQL statements such as `ALTER TABLE RENAME COLUMN` when available.
14881522

1489-
We can rename columns with the help of the `SchemaChanger` class:
1523+
#### Adding Columns
14901524

14911525
```swift
1526+
let newColumn = ColumnDefinition(
1527+
name: "new_text_column",
1528+
type: .TEXT,
1529+
nullable: true,
1530+
defaultValue: .stringLiteral("foo")
1531+
)
1532+
14921533
let schemaChanger = SchemaChanger(connection: db)
1534+
14931535
try schemaChanger.alter(table: "users") { table in
1494-
table.rename(column: "old_name", to: "new_name")
1536+
table.add(newColumn)
14951537
}
14961538
```
14971539

1498-
### Dropping Columns
1540+
#### Renaming Columns
14991541

15001542
```swift
15011543
let schemaChanger = SchemaChanger(connection: db)
15021544
try schemaChanger.alter(table: "users") { table in
1503-
table.drop(column: "email")
1545+
table.rename(column: "old_name", to: "new_name")
15041546
}
15051547
```
15061548

1507-
These operations will work with all versions of SQLite and use modern SQL
1508-
operations such as `DROP COLUMN` when available.
1509-
1510-
### Adding Columns (SchemaChanger)
1511-
1512-
The `SchemaChanger` provides an alternative API to add new columns:
1549+
#### Dropping Columns
15131550

15141551
```swift
1515-
let newColumn = ColumnDefinition(
1516-
name: "new_text_column",
1517-
type: .TEXT,
1518-
nullable: true,
1519-
defaultValue: .stringLiteral("foo")
1520-
)
1521-
15221552
let schemaChanger = SchemaChanger(connection: db)
1523-
15241553
try schemaChanger.alter(table: "users") { table in
1525-
table.add(newColumn)
1554+
table.drop(column: "email")
15261555
}
15271556
```
15281557

1529-
### Renaming/dropping Tables (SchemaChanger)
1530-
1531-
The `SchemaChanger` provides an alternative API to rename and drop tables:
1558+
#### Renaming/dropping Tables
15321559

15331560
```swift
15341561
let schemaChanger = SchemaChanger(connection: db)
15351562

15361563
try schemaChanger.rename(table: "users", to: "users_new")
1537-
try schemaChanger.drop(table: "emails")
1564+
try schemaChanger.drop(table: "emails", ifExists: false)
15381565
```
15391566

15401567
### Indexes
@@ -1592,25 +1619,6 @@ try db.run(users.dropIndex(email, ifExists: true))
15921619
// DROP INDEX IF EXISTS "index_users_on_email"
15931620
```
15941621

1595-
### Dropping Tables
1596-
1597-
We can build
1598-
[`DROP TABLE` statements](https://www.sqlite.org/lang_droptable.html)
1599-
by calling the `dropTable` function on a `SchemaType`.
1600-
1601-
```swift
1602-
try db.run(users.drop())
1603-
// DROP TABLE "users"
1604-
```
1605-
1606-
The `drop` function has one additional parameter, `ifExists`, which (when
1607-
`true`) adds an `IF EXISTS` clause to the statement.
1608-
1609-
```swift
1610-
try db.run(users.drop(ifExists: true))
1611-
// DROP TABLE IF EXISTS "users"
1612-
```
1613-
16141622
### Migrations and Schema Versioning
16151623

16161624
You can use the convenience property on `Connection` to query and set the
@@ -2183,7 +2191,7 @@ try db.detach("external")
21832191
// DETACH DATABASE 'external'
21842192
```
21852193

2186-
When compiled for SQLCipher, you can additionally pass a `key` parameter to `attach`:
2194+
When compiled for SQLCipher, we can additionally pass a `key` parameter to `attach`:
21872195

21882196
```swift
21892197
try db.attach(.uri("encrypted.sqlite"), as: "encrypted", key: "secret")

Documentation/Release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [ ] Make sure current master branch has a green build
44
* [ ] Make sure `SQLite.playground` runs without errors
55
* [ ] Make sure `CHANGELOG.md` is up-to-date
6+
* [ ] Add content to `Documentation/Upgrading.md` if needed
67
* [ ] Update the version number in `SQLite.swift.podspec`
78
* [ ] Run `pod lib lint` locally
89
* [ ] Update the version numbers mentioned in `README.md`, `Documentation/Index.md`

Documentation/Upgrading.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Upgrading
2+
3+
## 0.13 → 0.14
4+
5+
- `Expression.asSQL()` is no longer available. Expressions now implement `CustomStringConvertible`,
6+
where `description` returns the SQL.
7+
- `Statement.prepareRowIterator()` is now longer available. Instead, use the methods
8+
of the same name on `Connection`.
9+
- `Blob` no longer wraps byte arrays and now uses `NSData`, which enables memory and
10+
performance improvements.
11+
- `Connection.registerTokenizer` is no longer available to register custom FTS4 tokenizers.

README.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ syntax _and_ intent.
1919
- [Well-documented][See Documentation]
2020
- Extensively tested
2121
- [SQLCipher][] support via CocoaPods
22+
- [Schema query/migration][]
2223
- Works on [Linux](Documentation/Linux.md) (with some limitations)
2324
- Active support at
2425
[StackOverflow](https://stackoverflow.com/questions/tagged/sqlite.swift),
@@ -27,6 +28,7 @@ syntax _and_ intent.
2728

2829
[SQLCipher]: https://www.zetetic.net/sqlcipher/
2930
[Full-text search]: Documentation/Index.md#full-text-search
31+
[Schema query/migration]: Documentation/Index.md#querying-the-schema
3032
[See Documentation]: Documentation/Index.md#sqliteswift-documentation
3133

3234

@@ -115,17 +117,10 @@ interactively, from the Xcode project’s playground.
115117

116118
![SQLite.playground Screen Shot](Documentation/Resources/playground@2x.png)
117119

118-
For a more comprehensive example, see
119-
[this article][Create a Data Access Layer with SQLite.swift and Swift 2]
120-
and the [companion repository][SQLiteDataAccessLayer2].
121-
122-
123-
[Create a Data Access Layer with SQLite.swift and Swift 2]: https://masteringswift.blogspot.com/2015/09/create-data-access-layer-with.html
124-
[SQLiteDataAccessLayer2]: https://github.com/hoffmanjon/SQLiteDataAccessLayer2/tree/master
125-
126120
## Installation
127121

128-
> _Note:_ Version 0.11.6 and later requires Swift 5 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.2) or greater. Version 0.11.5 requires Swift 4.2 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.1) or greater.
122+
> _Note:_ Version 0.11.6 and later requires Swift 5 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.2) or greater.
123+
> Version 0.11.5 requires Swift 4.2 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.1) or greater.
129124
130125
### Swift Package Manager
131126

@@ -136,7 +131,7 @@ Swift code.
136131

137132
```swift
138133
dependencies: [
139-
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.13.3")
134+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.0")
140135
]
141136
```
142137

@@ -160,7 +155,7 @@ install SQLite.swift with Carthage:
160155
2. Update your Cartfile to include the following:
161156

162157
```ruby
163-
github "stephencelis/SQLite.swift" ~> 0.13.3
158+
github "stephencelis/SQLite.swift" ~> 0.14.0
164159
```
165160

166161
3. Run `carthage update` and
@@ -191,7 +186,7 @@ SQLite.swift with CocoaPods:
191186
use_frameworks!
192187
193188
target 'YourAppTargetName' do
194-
pod 'SQLite.swift', '~> 0.13.3'
189+
pod 'SQLite.swift', '~> 0.14.0'
195190
end
196191
```
197192

@@ -250,7 +245,7 @@ device:
250245
[Submit a pull request]: https://github.com/stephencelis/SQLite.swift/fork
251246

252247

253-
## Author
248+
## Original author
254249

255250
- [Stephen Celis](mailto:stephen@stephencelis.com)
256251
([@stephencelis](https://twitter.com/stephencelis))
@@ -267,19 +262,14 @@ These projects enhance or use SQLite.swift:
267262

268263
- [SQLiteMigrationManager.swift][] (inspired by
269264
[FMDBMigrationManager][])
270-
- [Delta: Math helper](https://apps.apple.com/app/delta-math-helper/id1436506800)
271-
(see [Delta/Utils/Database.swift](https://github.com/GroupeMINASTE/Delta-iOS/blob/master/Delta/Utils/Database.swift) for production implementation example)
272-
273265

274266
## Alternatives
275267

276268
Looking for something else? Try another Swift wrapper (or [FMDB][]):
277269

278-
- [Camembert](https://github.com/remirobert/Camembert)
279270
- [GRDB](https://github.com/groue/GRDB.swift)
280271
- [SQLiteDB](https://github.com/FahimF/SQLiteDB)
281272
- [Squeal](https://github.com/nerdyc/Squeal)
282-
- [SwiftData](https://github.com/ryanfowler/SwiftData)
283273

284274
[Swift]: https://swift.org/
285275
[SQLite3]: https://www.sqlite.org

SQLite.playground/Contents.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ for user in try Array(rowIterator) {
5252

5353
/// also with `map()`
5454
let mapRowIterator = try db.prepareRowIterator(users)
55+
5556
let userIds = try mapRowIterator.map { $0[id] }
5657

5758
/// using `failableNext()` on `RowIterator`

SQLite.swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SQLite.swift"
3-
s.version = "0.13.3"
3+
s.version = "0.14.0"
44
s.summary = "A type-safe, Swift-language layer over SQLite3."
55

66
s.description = <<-DESC

0 commit comments

Comments
 (0)