You are looking at historical revision 28243 of this page. It may differ significantly from its current revision.

couchdb-view-server

Description

Implements a Scheme view server for Apache CouchDB.

Deprecation Notice

This egg is no longer maintained and is known not to work with recent Chicken versions (at least since 4.8.x). Please get in touch with the author if you want to adopt maintenance.

Author

Moritz Heidkamp

Requirements

Requires the environments and json eggs. Also, for it to be somewhat useful, you need a CouchDB server with the following setting in the [query_servers] config section:

  scheme = /usr/bin/chicken-couchdb

The path to chicken-couchdb may be different on your system, of course.

You can now use "scheme" as a view language.

Documentation

Within your map and reduce definitions, you have access to all R5RS procedures as well as those from SRFI-1. There is a binding for null which contains the result of (void) i.e. #<unspecified> and can be used to generate JSON nulls. The following procedures are also available:

emit

[procedure] (emit key value)

Just like in the default JavaScript view server, emit is implicitly available and is used to emit results from the map function.

ref

[procedure] (ref key doc)

Allows accessing values in avectors by key (json uses these to represent JSON objects).

Example:

(ref 'foo '#((foo . bar)))
=> bar

log

[procedure] (log message)

Can be used to make the CouchDB server log a message.

Example

{
   "_id": "_design/foo",
   "_rev": "1-8e9036611c14d4ffe34e9065a3a33683",
   "language": "scheme",
   "views": {
       "by-created-at": {
           "map": "(lambda (doc) (let ((title (ref 'title doc)))
				   (if title (begin
					       (log (string-append \"mapping \" title))
					       (emit null (ref 'created-at doc))))))",
           "reduce": "(lambda (k v r) (fold + 0 v))"
       }
   }
}