From df748e5e75607c95ab65430ff6ae989a68a5ba96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 23 Mar 2016 08:19:05 +0100 Subject: [PATCH] README.md --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0049b02d4..f79019a6e 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,8 @@ dbQueue.inDatabase { db in *If you know what you are doing*, you can skip the protection of `inDatabase`, and use the queue directly, as below. In a multithreaded application, two consecutive statements could then potentially run on an unstable database state (see [Concurrency](#concurrency)): ```swift -// Direct access, for advanced users only: +// Unprotected access, for advanced users only: +try PointOfInterest(...).insert(dbQueue) let pois = PointOfInterest.fetchAll(dbQueue) ``` @@ -318,7 +319,8 @@ dbPool.read { db in *If you know what you are doing*, you can skip the protection of `read`, `write` and `writeInTransaction`, and use the pool directly, as below. In a multithreaded application, two consecutive statements could then potentially run on an unstable database state (see [Concurrency](#concurrency)): ```swift -// Direct access, for advanced users only: +// Unprotected access, for advanced users only: +try PointOfInterest(...).insert(dbPool) let pois = PointOfInterest.fetchAll(dbPool) ``` @@ -2531,7 +2533,7 @@ dbQueue.inDatabase { db in // or dbPool.read, or dbPool.write } ``` -This is very different from the direct access to queue and pools. The two lines below are equivalent to two consecutive calls to `inDatabase`, with the opportunity for other threads to sneak in: +*The unprotected access to queue and pools is very different.* The two lines below are equivalent to two consecutive calls to `dbQueue.inDatabase` or `dbPool.read`, with the opportunity for other threads to sneak in the middle: ```swift // Those two values may be different because some other thread may have inserted @@ -2540,6 +2542,15 @@ let count1 = PointOfInterest.fetchCount(dbQueue) // or dbPool let count2 = PointOfInterest.fetchCount(dbQueue) // or dbPool ``` +That being said, unprotected access can do everything but iterate the memory-efficient [database sequences](#fetching-methods): + +```swift +try dbQueue.execute("INSERT ...") +let rows = Row.fetchAll(dbQueue, "SELECT ...") +try PointOfInterest(...).insert(dbQueue) +let pois = PointOfInterest.filter(favorite).order(title).fetchAll(dbQueue) +``` + **Rule 2: Use the safe `inDatabase`, `inTransaction`, `read`, `write` and `writeInTransaction` methods unless you know what you are doing.**