On Wed, Apr 29, 2009 at 1:27 PM, dmi <[email protected]> wrote:
> Hi, All!
>
> I would like to suggest some way to have library functions in the javascript
> (or other) views.
>
> Currently, if I have some structured entries and a bunch of "library"
> functions to peek values from them, which are highly used in many views, I
> have two possible ways:
>
> 1. to include the library functions in the each view;
> 2. to patch couchdb's main.js and to include the library in it.
>
> Both ways are ugly, imho...
>
> I realize, it would be cool to have, say, "/_library/libname" document with
> the library body.
> And to have the optional parameter 'library' in the view's definition:
>
> {'map': 'function body', 'reduce': 'function body', 'library': ['libname',
> ....]}
>
> so when couchdb pass the view's functions to the view server it will pass not
> only 'add_fun', but also 'add_lib' command with the library body to evaluate
> in the view execution environment.
>
> Unfortunately, I'm far from being an expert in couchdb ideology to propose
> more constructive ideas about :-)
>
Please check out the CouchApp toolkit. It is a script which pushes
your filesystem into CouchDB design documents. It has the capability
to inline library code into your view/etc functions.
There are a lot of reasons why we've chosen the single monolithic
function approach. Check the list archives for discussions.
("couchapp", "include", and "macro" are the search terms I'd start
with.)
Chris
--
Chris Anderson
http://jchrisa.net
http://couch.io