From 06a9a7c39918f02bbaaa1ae46b0ca04fadb1aa91 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 3 Sep 2013 22:55:01 -0700 Subject: [PATCH] Document lazy queries --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 2a5035f3..f8e54396 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,22 @@ do conn.in_transaction |trans| { ``` A transaction will commit by default. Transactions cannot currently be nested. +Lazy Queries +------------ +Some queries may return a large amount of data. Inside of a transaction, +prepared statements have an additional method, `lazy_query`. The rows returned +from a call to `lazy_query` are pulled from the database lazily as needed: +```rust +do conn.in_transaction |trans| { + let stmt = trans.prepare(query) + + // No more than 100 rows will be stored in memory at any time + for row in stmt.lazy_query(100, params) { + // do things + } +} +``` + Error Handling -------------- The methods described above will fail if there is an error. For each of these