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:
Cleanup and, hopefully, clarifications

------------------------------------------------------------------------------
  }
  }}}
  
- These functions could be queried like this:
+ Assuming these functions were in a design document named "`examples`" in a 
database named "`db`", they could be queried like this:
  
  {{{
  GET /db/_show/examples/posts/somedocid
@@ -30, +30 @@

  }}}
  
  
- The show function is run with two arguments, the first is the document 
corresponding to the requested docid. The second argument is the req object, 
which contains information about the query string, Accept headers, and other 
per-request information.
+ The `show` function is run with two arguments. The first is the document 
corresponding to the requested `docid`, and the second describes the HTTP 
request's query string, Accept headers, and other per-request information. The 
function returns an object describing its HTTP response.
  
- The show function returns a JSON object of the same format of the _external 
response. See ExternalProcesses for further explanation of the `req` object as 
well as documentation about the response.
+ The request and response objects are of the same format used by `_external` 
functions, as documented in ExternalProcesses.
  
  == Listing Views ==
  
- List funcitons are stored under the `lists` key of design documents. Here's 
an example desgin doc with list functions:
+ List functions are stored under the `lists` key of a design document. Here's 
an example design doc with list functions, in addition to views:
  
  {{{
  {
@@ -60, +60 @@

  GET /db/_list/examples/index-posts/posts-by-tag?key="howto"
  
  GET /db/_list/examples/browse-people/people-by-name?startkey=["a"]&limit=10
- 
  }}}
  
- List functions have a more interesting signature, as they are passed the head 
of the view on first invocation, then each row in turn, then called once 
finally for the tail of the view. They also have the ability to abort iteration 
early, which is handy for some filtering operations.
+ [As above, we assume the database is named "db" and the design doc 
"examples".]
+ 
+ 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(false, rows[0], req, row_info);  // First row: head=false
+   listfn(false, rows[1], req, row_info);  // Subsequent rows...
+   listfn(false, rows[2], req, row_info);
+   listfn(false, 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.
  
  Example list function:
  
@@ -79, +90 @@

  }
  }}}
  
- Hopefully that gets you enough to get started. For a more complete set of 
examples, see the CouchDB test suite, especially show_documents.js and 
list_views.js
+ Hopefully this is enough to get started. For a more complete set of examples, 
see the CouchDB test suite, especially show_documents.js and list_views.js
  

Reply via email to