couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject Re: Extending main.js
Date Thu, 25 Sep 2008 16:27:40 GMT
On Thu, Sep 25, 2008 at 8:32 AM, kowsik <> wrote:
> I'm thinking we should
> have a REST method to add additional app-specific methods that are
> available to the map/reduce function? These could be utility methods
> or static lookup tables and so on.

The danger with this approach is that you absolutely need the source
code for each map and reduce function to correspond 1-1 with its
behavior. Otherwise, behavior could change without expiring the view

I wrestled with the problem for while, before I realized that there's
no harm in including library code directly into maps and reduces. I've
got some scripts in the CouchRest project that upload filesystem code
to design documents, inlining the contents of a lib.js file into your
maps or reduces, if you include a comment like


within your function. This way I don't repeat myself, but each map and
reduce function contains its full specification.

CouchRest is located here:

Once you've installed the gem, run

couchview --help generate

to get a feel for the directory structure it's looking for.

Chris Anderson

View raw message