You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "A.J. Brown" <aj...@ajbrown.org> on 2010/07/16 18:10:44 UTC

Custom / Global view functions?

Hello fellow CouchDBians,

Is there any method for writing functions which can be accessed by any
of my views?  Quite a few of my views require the same functionality
to filter documents or parse certain fields, and it would be a shame
to have to maintain that code in every single view.

-- 
A.J. Brown
Software Engineer, ZCE
blog : http://ajbrown.org
talk  : (937) 540-0099
chat : IntypicaAJ

Re: Custom / Global view functions?

Posted by J Chris Anderson <jc...@gmail.com>.
On Jul 16, 2010, at 10:57 AM, Mikeal Rogers wrote:

> We also support commonjs modules which I would now consider the "preferred"
> way to do this. Macros were nice but required tooling, now modules are baked
> in to the view server. You can also load these modules in jquery.couch.js in
> the browser as well.
> 
> http://wiki.apache.org/couchdb/CommonJS_Modules
> 

except you can't do commonjs in views because we cache the view based on the byte string of the function itself. so we don't allow external dependencies because you could end up with an inconsistent view that way.

> -Mikeal
> 
> On Fri, Jul 16, 2010 at 9:21 AM, Robert Newson <ro...@gmail.com>wrote:
> 
>> CouchApp has !code and !json macros to aid view code reuse. View
>> functions are required to be self-contained.
>> 
>> http://github.com/couchapp/couchapp
>> 
>> B.
>> 
>> On Fri, Jul 16, 2010 at 12:10 PM, A.J. Brown <aj...@ajbrown.org> wrote:
>>> Hello fellow CouchDBians,
>>> 
>>> Is there any method for writing functions which can be accessed by any
>>> of my views?  Quite a few of my views require the same functionality
>>> to filter documents or parse certain fields, and it would be a shame
>>> to have to maintain that code in every single view.
>>> 
>>> --
>>> A.J. Brown
>>> Software Engineer, ZCE
>>> blog : http://ajbrown.org
>>> talk  : (937) 540-0099
>>> chat : IntypicaAJ
>>> 
>> 


Re: Custom / Global view functions?

Posted by Mikeal Rogers <mi...@gmail.com>.
We also support commonjs modules which I would now consider the "preferred"
way to do this. Macros were nice but required tooling, now modules are baked
in to the view server. You can also load these modules in jquery.couch.js in
the browser as well.

http://wiki.apache.org/couchdb/CommonJS_Modules

-Mikeal

On Fri, Jul 16, 2010 at 9:21 AM, Robert Newson <ro...@gmail.com>wrote:

> CouchApp has !code and !json macros to aid view code reuse. View
> functions are required to be self-contained.
>
> http://github.com/couchapp/couchapp
>
> B.
>
> On Fri, Jul 16, 2010 at 12:10 PM, A.J. Brown <aj...@ajbrown.org> wrote:
> > Hello fellow CouchDBians,
> >
> > Is there any method for writing functions which can be accessed by any
> > of my views?  Quite a few of my views require the same functionality
> > to filter documents or parse certain fields, and it would be a shame
> > to have to maintain that code in every single view.
> >
> > --
> > A.J. Brown
> > Software Engineer, ZCE
> > blog : http://ajbrown.org
> > talk  : (937) 540-0099
> > chat : IntypicaAJ
> >
>

Re: Custom / Global view functions?

Posted by Robert Newson <ro...@gmail.com>.
CouchApp has !code and !json macros to aid view code reuse. View
functions are required to be self-contained.

http://github.com/couchapp/couchapp

B.

On Fri, Jul 16, 2010 at 12:10 PM, A.J. Brown <aj...@ajbrown.org> wrote:
> Hello fellow CouchDBians,
>
> Is there any method for writing functions which can be accessed by any
> of my views?  Quite a few of my views require the same functionality
> to filter documents or parse certain fields, and it would be a shame
> to have to maintain that code in every single view.
>
> --
> A.J. Brown
> Software Engineer, ZCE
> blog : http://ajbrown.org
> talk  : (937) 540-0099
> chat : IntypicaAJ
>