From commits-return-1845-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Sun Feb 22 02:27:41 2009 Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 55924 invoked from network); 22 Feb 2009 02:27:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Feb 2009 02:27:41 -0000 Received: (qmail 20520 invoked by uid 500); 22 Feb 2009 02:27:41 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 20490 invoked by uid 500); 22 Feb 2009 02:27:41 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 20481 invoked by uid 500); 22 Feb 2009 02:27:41 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 20478 invoked by uid 99); 22 Feb 2009 02:27:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Feb 2009 18:27:41 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO aurora.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Feb 2009 02:27:39 +0000 Received: from aurora.apache.org (localhost [127.0.0.1]) by aurora.apache.org (8.13.8+Sun/8.13.8) with ESMTP id n1M2RJZO022604 for ; Sun, 22 Feb 2009 02:27:19 GMT Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: couchdb-commits@incubator.apache.org Date: Sun, 22 Feb 2009 02:27:19 -0000 Message-ID: <20090222022719.22304.92562@aurora.apache.org> Subject: [Couchdb Wiki] Update of "Formatting with Show and List" by ChrisAnderson X-Virus-Checked: Checked by ClamAV on apache.org 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 ChrisAnderson: http://wiki.apache.org/couchdb/Formatting_with_Show_and_List The comment on the change is: documentation for list funs ------------------------------------------------------------------------------ == Listing Views == + List funcitons are stored under the `lists` key of design documents. Here's an example desgin doc with list functions: + + {{{ + { + "_id" : "_design/examples", + "views" { + "posts-by-date" : "function(doc){...}", + "posts-by-tag" : "function(doc){...}", + "people-by-name" : "function(doc) {...}" + }, + "lists" : { + "index-posts" : "function(head, row, req, row_info) {...}", + "browse-people" : "function(head, row, req, row_info) { ... }" + } + }}} + + These lists are run by querying URLs like: + + {{{ + GET /db/_list/examples/index-posts/posts-by-date?descending=true&limit=10 + + 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. + + Example list function: + + {{{ + function(head, row, req, row_info) { + if (head) { + return "

head: "+JSON.stringify(head)+"

    ""; + } else if (row) { + return "
  • "+JSON.stringify(row)+"
  • "; + } else { + return "

the tail

" + } + } + }}} + + 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 +