9
9
- [ Connecting to a Database] ( #connecting-to-a-database )
10
10
- [ Read-Write Databases] ( #read-write-databases )
11
11
- [ Read-Only Databases] ( #read-only-databases )
12
+ - [ In a Shared Group Container] ( #in-a-shared-group-container )
12
13
- [ In-Memory Databases] ( #in-memory-databases )
13
14
- [ URI parameters] ( #uri-parameters )
14
15
- [ Thread-Safety] ( #thread-safety )
41
42
- [ Updating Rows] ( #updating-rows )
42
43
- [ Deleting Rows] ( #deleting-rows )
43
44
- [ Transactions and Savepoints] ( #transactions-and-savepoints )
45
+ - [ Querying the Schema] ( #querying-the-schema )
44
46
- [ Altering the Schema] ( #altering-the-schema )
45
47
- [ Renaming Tables] ( #renaming-tables )
48
+ - [ Dropping Tables] ( #dropping-tables )
46
49
- [ Adding Columns] ( #adding-columns )
47
50
- [ 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 )
48
55
- [ Indexes] ( #indexes )
49
56
- [ Creating Indexes] ( #creating-indexes )
50
57
- [ Dropping Indexes] ( #dropping-indexes )
51
- - [ Dropping Tables] ( #dropping-tables )
52
58
- [ Migrations and Schema Versioning] ( #migrations-and-schema-versioning )
53
59
- [ Custom Types] ( #custom-types )
54
60
- [ Date-Time Values] ( #date-time-values )
@@ -83,7 +89,7 @@ process of downloading, compiling, and linking dependencies.
83
89
84
90
``` swift
85
91
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 " )
87
93
]
88
94
```
89
95
@@ -104,7 +110,7 @@ install SQLite.swift with Carthage:
104
110
2 . Update your Cartfile to include the following:
105
111
106
112
``` ruby
107
- github " stephencelis/SQLite.swift" ~ > 0.13 . 3
113
+ github " stephencelis/SQLite.swift" ~ > 0.14 . 0
108
114
```
109
115
110
116
3 . Run ` carthage update` and [add the appropriate framework][Carthage Usage ].
@@ -134,7 +140,7 @@ install SQLite.swift with Carthage:
134
140
use_frameworks!
135
141
136
142
target 'YourAppTargetName' do
137
- pod 'SQLite.swift', '~> 0.13.3 '
143
+ pod 'SQLite.swift', '~> 0.14.0 '
138
144
end
139
145
` ` `
140
146
@@ -148,7 +154,7 @@ with the OS you can require the `standalone` subspec:
148
154
149
155
` ` ` ruby
150
156
target 'YourAppTargetName' do
151
- pod 'SQLite.swift/standalone', '~> 0.13.3 '
157
+ pod 'SQLite.swift/standalone', '~> 0.14.0 '
152
158
end
153
159
` ` `
154
160
@@ -158,7 +164,7 @@ dependency to sqlite3 or one of its subspecs:
158
164
159
165
` ` ` ruby
160
166
target 'YourAppTargetName' do
161
- pod 'SQLite.swift/standalone', '~> 0.13.3 '
167
+ pod 'SQLite.swift/standalone', '~> 0.14.0 '
162
168
pod 'sqlite3/fts5', '= 3.15.0' # SQLite 3.15.0 with FTS5 enabled
163
169
end
164
170
` ` `
@@ -168,13 +174,13 @@ See the [sqlite3 podspec][sqlite3pod] for more details.
168
174
# ### Using SQLite.swift with SQLCipher
169
175
170
176
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)) :
172
178
173
179
` ` ` ruby
174
180
target 'YourAppTargetName' do
175
181
# Make sure you only require the subspec, otherwise you app might link against
176
182
# 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 '
178
184
end
179
185
` ` `
180
186
@@ -325,6 +331,13 @@ let db = try Connection(path, readonly: true)
325
331
> We welcome changes to the above sample code to show how to successfully copy and use a bundled " seed"
326
332
> database for writing in an app.
327
333
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
+
328
341
# ### In-Memory Databases
329
342
330
343
If you omit the path, SQLite .swift will provision an [in - memory
@@ -1409,7 +1422,6 @@ for column in columns {
1409
1422
SQLite.swift comes with several functions (in addition to `Table.create `) for
1410
1423
altering a database schema in a type- safe manner.
1411
1424
1412
-
1413
1425
### Renaming Tables
1414
1426
1415
1427
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")))
1420
1432
// ALTER TABLE "users" RENAME TO "users_old"
1421
1433
```
1422
1434
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
+ ```
1423
1453
1424
1454
### Adding Columns
1425
1455
@@ -1484,57 +1514,54 @@ tables](#creating-a-table).
1484
1514
// ALTER TABLE "posts" ADD COLUMN "user_id" INTEGER REFERENCES "users" ("id")
1485
1515
```
1486
1516
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.
1488
1522
1489
- We can rename columns with the help of the `SchemaChanger` class :
1523
+ #### Adding Columns
1490
1524
1491
1525
```swift
1526
+ let newColumn = ColumnDefinition (
1527
+ name : " new_text_column" ,
1528
+ type : .TEXT ,
1529
+ nullable : true ,
1530
+ defaultValue : .stringLiteral (" foo" )
1531
+ )
1532
+
1492
1533
let schemaChanger = SchemaChanger (connection : db)
1534
+
1493
1535
try schemaChanger.alter (table : " users" ) { table in
1494
- table.rename ( column : " old_name " , to : " new_name " )
1536
+ table.add (newColumn )
1495
1537
}
1496
1538
```
1497
1539
1498
- ### Dropping Columns
1540
+ #### Renaming Columns
1499
1541
1500
1542
```swift
1501
1543
let schemaChanger = SchemaChanger (connection : db)
1502
1544
try schemaChanger.alter (table : " users" ) { table in
1503
- table.drop (column : " email " )
1545
+ table.rename (column : " old_name " , to : " new_name " )
1504
1546
}
1505
1547
```
1506
1548
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
1513
1550
1514
1551
```swift
1515
- let newColumn = ColumnDefinition (
1516
- name : " new_text_column" ,
1517
- type : .TEXT ,
1518
- nullable : true ,
1519
- defaultValue : .stringLiteral (" foo" )
1520
- )
1521
-
1522
1552
let schemaChanger = SchemaChanger (connection : db)
1523
-
1524
1553
try schemaChanger.alter (table : " users" ) { table in
1525
- table.add (newColumn )
1554
+ table.drop ( column : " email " )
1526
1555
}
1527
1556
```
1528
1557
1529
- ### Renaming/ dropping Tables (SchemaChanger)
1530
-
1531
- The `SchemaChanger` provides an alternative API to rename and drop tables:
1558
+ #### Renaming/ dropping Tables
1532
1559
1533
1560
```swift
1534
1561
let schemaChanger = SchemaChanger (connection : db)
1535
1562
1536
1563
try schemaChanger.rename (table : " users" , to : " users_new" )
1537
- try schemaChanger.drop (table : " emails" )
1564
+ try schemaChanger.drop (table : " emails" , ifExists : false )
1538
1565
```
1539
1566
1540
1567
### Indexes
@@ -1592,25 +1619,6 @@ try db.run(users.dropIndex(email, ifExists: true))
1592
1619
// DROP INDEX IF EXISTS "index_users_on_email"
1593
1620
```
1594
1621
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
-
1614
1622
### Migrations and Schema Versioning
1615
1623
1616
1624
You can use the convenience property on `Connection` to query and set the
@@ -2183,7 +2191,7 @@ try db.detach("external")
2183
2191
// DETACH DATABASE 'external'
2184
2192
```
2185
2193
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`:
2187
2195
2188
2196
```swift
2189
2197
try db.attach (.uri (" encrypted.sqlite" ), as : " encrypted" , key : " secret" )
0 commit comments