couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Formatting with Show and List" by JensAlfke
Date Tue, 24 Feb 2009 06:11:52 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by JensAlfke:
http://wiki.apache.org/couchdb/Formatting_with_Show_and_List

The comment on the change is:
Added details about 'head' and 'row_info'.

------------------------------------------------------------------------------
  A list function has a more interesting signature, as it is passed the head of the view on
first invocation, then each row in turn, then called one more time for the tail of the view.
The function should check the `head` and `row` parameters to identify which state it's being
called in; the sequence of calls to `listfn`, for a view with three rows, would look like:
  
  {{{
-   listfn(true,  null   , req, null    );  // Before the first row: head=true
+   listfn(head, null,    req, null    );  // Before the first row: head is non-null
-   listfn(false, rows[0], req, row_info);  // First row: head=false
+   listfn(null, rows[0], req, row_info);  // First row
-   listfn(false, rows[1], req, row_info);  // Subsequent rows...
+   listfn(null, rows[1], req, row_info);  // Subsequent rows...
-   listfn(false, rows[2], req, row_info);
+   listfn(null, rows[2], req, row_info);
-   listfn(false, null,    req, row_info);  // After last row: row=null
+   listfn(null, null,    req, row_info);  // After last row: row=null
  }}}
  
- List functions also have the ability to abort iteration early, which is handy for some filtering
operations.
+ The `head` parameter -- which is only passed into the first call -- contains an object with
information about the view that is to be iterated over. It's much like the response object
returned from a view query in the CouchDB JavaScript API; useful properties include `total_rows`
and `offset`.
+ 
+ The `row_info` parameter contains an object with information about the iteration state.
Its properties include:
+ * `row_number` (the current row number)
+ * `first_key` (the first key of the view to be listed)
+ * `prev_key` (the key of the row in the previous iteration)
  
  Example list function:
  

Mime
View raw message