couchdb-view-server
Description
Implements a Scheme view server for Apache CouchDB.
Author
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
- (emit key value) procedure
Just like in the default JavaScript view server, emit is implicitly available and is used to emit results from the map function.
ref
- (ref key doc) procedure
Allows accessing values in avectors by key (json uses these to represent JSON objects).
Example:
(ref 'foo '#((foo . bar))) => bar
log
- (log message) procedure
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))"
}
}
}