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 )
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
150156target 'YourAppTargetName' do
151- pod 'SQLite.swift/standalone', '~> 0.13.3 '
157+ pod 'SQLite.swift/standalone', '~> 0.14.0 '
152158end
153159` ` `
154160
@@ -158,7 +164,7 @@ dependency to sqlite3 or one of its subspecs:
158164
159165` ` ` ruby
160166target '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
163169end
164170` ` `
@@ -168,13 +174,13 @@ See the [sqlite3 podspec][sqlite3pod] for more details.
168174# ### Using SQLite.swift with SQLCipher
169175
170176If 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
174180target '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 '
178184end
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
330343If you omit the path, SQLite .swift will provision an [in - memory
@@ -1409,7 +1422,6 @@ for column in columns {
14091422SQLite.swift comes with several functions (in addition to `Table.create `) for
14101423altering a database schema in a type- safe manner.
14111424
1412-
14131425### Renaming Tables
14141426
14151427We 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+
14921533let schemaChanger = SchemaChanger (connection : db)
1534+
14931535try 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
15011543let schemaChanger = SchemaChanger (connection : db)
15021544try 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-
15221552let schemaChanger = SchemaChanger (connection : db)
1523-
15241553try 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
15341561let schemaChanger = SchemaChanger (connection : db)
15351562
15361563try 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
16161624You 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
21892197try db.attach (.uri (" encrypted.sqlite" ), as : " encrypted" , key : " secret" )
0 commit comments