You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -111,8 +112,26 @@ install SQLite.swift with Carthage:
111
112
112
113
3. Run `pod install`.
113
114
115
+
#### Requiring a specific version of SQLite
116
+
117
+
If you want to use a more recent version of SQLite than what is provided with the OS you can require the `standalone` subspec:
118
+
119
+
``` ruby
120
+
pod 'SQLite.swift/standalone', '~> 0.10.1'
121
+
```
122
+
123
+
By default this will use the most recent version of SQLite without any extras. If you want you can further customize this by adding another dependency to sqlite3 or one of its subspecs:
124
+
125
+
```ruby
126
+
pod 'SQLite.swift/standalone', '~> 0.10.1'
127
+
pod 'sqlite3/fts5', '= 3.11.1'# SQLite 3.11.1 with FTS5 enabled
128
+
```
129
+
130
+
See the [sqlite3 podspec][sqlite3pod] for more details.
@@ -233,7 +252,7 @@ Every Connection comes equipped with its own serial queue for statement executio
233
252
234
253
If you maintain multiple connections for a single database, consider setting a timeout (in seconds) and/or a busy handler:
235
254
236
-
```swift
255
+
```swift
237
256
db.busyTimeout =5
238
257
239
258
db.busyHandler({ tries in
@@ -247,6 +266,33 @@ db.busyHandler({ tries in
247
266
> _Note:_ The default timeout is0, so if you see `database is locked` errors, you may be trying to access the same database simultaneously from multiple connections.
248
267
249
268
269
+
### Connection Pools
270
+
271
+
Connection pools use SQLite WAL mode to allow concurrent reads and writes, which can increase performance. Connection pools are created similar to connections:
272
+
273
+
``` swift
274
+
let pool =tryConnectionPool("path/to/db.sqlite3")
275
+
```
276
+
277
+
Writes are done inside of a readWrite block:
278
+
279
+
``` swift
280
+
pool.readWrite { connection in
281
+
try connection.run(users.insert(email <-"[email protected]", name <-"Alice"))
SQLite.swift comes with a typed expression layer that directly maps [Swift types](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/SwiftStandardLibraryReference/) to their [SQLite counterparts](https://www.sqlite.org/datatype3.html).
Once we insert a few rows, we can search using the `match` function, which takes a table or column as its first argument and a query string as its second.
1385
1447
1386
1448
``` swift
@@ -1396,6 +1458,22 @@ let replies = emails.filter(subject.match("Re:*"))
1396
1458
// SELECT * FROM "emails" WHERE "subject" MATCH 'Re:*'
1397
1459
```
1398
1460
1461
+
### FTS5
1462
+
1463
+
When linking against a version of SQLite with [FTS5](http://www.sqlite.org/fts5.html) enabled we can create the virtual table
1464
+
in a similar fashion.
1465
+
1466
+
```swift
1467
+
let emails =VirtualTable("emails")
1468
+
let subject = Expression<String>("subject")
1469
+
let body = Expression<String>("body")
1470
+
let config =FTS5Config()
1471
+
.column(subject)
1472
+
.column(body, [.unindexed])
1473
+
1474
+
try db.run(emails.create(.FTS5(config))
1475
+
// CREATE VIRTUAL TABLE "emails" USING fts5("subject", "body" UNINDEXED)
0 commit comments