From a4647503604d52d5985cde6c65a80cee2b116563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jul 2015 23:43:41 +0200 Subject: [PATCH] Remove warning about lazy sequences iterated outside of database queue until we can document this in a less stressful way --- README.md | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/README.md b/README.md index 8d15cf7c6..d63cc00cb 100644 --- a/README.md +++ b/README.md @@ -129,42 +129,6 @@ db.fetchRows("SELECT * FROM persons WHERE name = :name", bindings: ["name": "Art ``` -**Rows sequences are lazy**: they iterates SQLite results as it they are consumed. - -If you iterate such a sequence out of a database queue, you will get a *fatal error*: - -```swift -// WRONG: you must not extract sequences out of a database queue. -let rowSequence = dbQueue.inDatabase { db in - db.fetchRows("SELECT ...") -} - -// fatal error: SelectStatement was not iterated on its database queue. -for row in rowSequence { - ... -} -``` - -The solution is to dump such a sequence into an array: - -```swift -// GOOD: Arrays of rows can safely be used outside of a database queue -let rows = dbQueue.inDatabase { db in - // The `fetchAllRows` variant returns an array of rows: - return db.fetchAllRows("SELECT ...") - - // Generally, any non-lazy collection will do: - return Array(db.fetchRows("SELECT ...")) - return db.fetchRows("SELECT ...").filter { ... } -} - -// Safely iterate rows: -for row in rows { - ... -} -``` - - **Extract row values** by index or column name: ```swift @@ -185,7 +149,7 @@ dbQueue.inDatabase { db in } ``` -**Rows themselves are sequences** of (column name, value) pairs: +**Rows themselves are sequences** of (column name, value) tuples: ```swift let row = db.fetchOneRow("SELECT firstName, lastName FROM persons")!