Skip to content

Commit da2d434

Browse files
committed
Merge pull request stephencelis#284 from patr1ck/master
Add threading info to documentation
2 parents ac517bf + 9790d21 commit da2d434

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Documentation/Index.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- [Read-Write Databases](#read-write-databases)
1111
- [Read-Only Databases](#read-only-databases)
1212
- [In-Memory Databases](#in-memory-databases)
13-
- [A Note on Thread-Safety](#a-note-on-thread-safety)
13+
- [Thread-Safety](#thread-safety)
1414
- [Building Type-Safe SQL](#building-type-safe-sql)
1515
- [Expressions](#expressions)
1616
- [Compound Expressions](#compound-expressions)
@@ -155,7 +155,7 @@ import SQLite
155155

156156
### Connecting to a Database
157157

158-
Database connections are established using the `Database` class. A database is initialized with a path. SQLite will attempt to create the database file if it does not already exist.
158+
Database connections are established using the `Connection` class. A connection is initialized with a path to a database. SQLite will attempt to create the database file if it does not already exist.
159159

160160
``` swift
161161
let db = try Connection("path/to/db.sqlite3")
@@ -220,9 +220,24 @@ let db = try Connection(.Temporary)
220220
In-memory databases are automatically deleted when the database connection is closed.
221221

222222

223-
### A Note on Thread-Safety
223+
#### Thread-Safety
224224

225-
> _Note:_ Every database comes equipped with its own serial queue for statement execution and can be safely accessed across threads. Threads that open transactions and savepoints will block other threads from executing statements while the transaction is open.
225+
Every Connection comes equipped with its own serial queue for statement execution and can be safely accessed across threads. Threads that open transactions and savepoints will block other threads from executing statements while the transaction is open.
226+
227+
If you maintain multiple connections for a single database, consider setting a timeout (in seconds) and/or a busy handler:
228+
229+
```swift
230+
db.busyTimeout = 5
231+
232+
db.busyHandler({ tries in
233+
if tries >= 3 {
234+
return false
235+
}
236+
return true
237+
})
238+
```
239+
240+
> _Note:_ The default timeout is 0, so if you see `database is locked` errors, you may be trying to access the same database simultaneously from multiple connections.
226241

227242

228243
## Building Type-Safe SQL

0 commit comments

Comments
 (0)