From d9ce97f0cf44692b28138e4dc7f8fbe6648fcf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 24 Sep 2015 04:56:23 +0200 Subject: [PATCH] README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 145660184..7ac6064be 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,7 @@ Row.fetch(db, "SELECT * FROM persons WHERE name = ?", arguments: ["Arthur"]) Row.fetch(db, "SELECT * FROM persons WHERE name = :name", arguments: ["name": "Arthur"]) ``` + **Row sequences grant direct access to SQLite**, and are generally faster than row arrays. Yet: - Don't consume row sequences outside of a database queue. Extract arrays instead: @@ -263,7 +264,9 @@ Row.fetch(db, "SELECT * FROM persons WHERE name = :name", arguments: ["name": "A for row in rows { ... } // OK ``` -- Fetched rows are reused during the sequence iteration: make sure you make a copy whenever you extract a row for later use: `row.copy()`. +- Fetched rows are reused during the sequence iteration: don't wrap a row sequence in an array with `Array(rows)` or `rows.filter { ... }` since you would not get the distinct rows you expect. Use `Row.fetchAll(...)` instead. + +- For the same reason, make sure you make a copy whenever you extract a row for later use: `row.copy()`. **Read row values** by index or column name: @@ -299,6 +302,7 @@ row.value(...) as! Int // NO NO NO DON'T DO THAT! row.value(...) as? Int // NO NO NO DON'T DO THAT! ``` + ##### Rows as Dictionaries The `row.value(named:)` and `row.value(atIndex:)` methods above require that you know the row structure: which columns are available, in which order.