You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Anthony Eden <an...@gmail.com> on 2008/11/20 13:09:09 UTC

Adding JS Libraries for Views?

What is the best way to add JavaScript libraries to CouchDB so that
they may be used in JavaScript views?

I was thinking of somehow adding libraries to
/usr/local/share/couchdb/server/main.js however I'm reluctant to just
jump straight into doing this since it seems like a brute force way to
solve a problem that must be better accomplished with a more elegant
solution.

Any suggestions?

Thanks!

Sincerely,
Anthony Eden

Re: Adding JS Libraries for Views?

Posted by Kerr Rainey <ke...@rokera.com>.
2008/11/21 Chris Anderson <jc...@apache.org>:
> this is good because you want the view to be erased if you change the
> code that generates it.

Yes, there is certainly a dependency.  If there was a separate design
doc that held js libs for a view, then you would want updates to the
lib to trigger a rebuild of the view.

But having tools that will put the lib ib the view doc automatically
is a pretty good work around.

--
Kerr

Re: Adding JS Libraries for Views?

Posted by Chris Anderson <jc...@apache.org>.
I include the text from libs inline in the view function itself.

CouchRest has a helper called "couchview" that does this according to
some conventions that worked for me.

it ends up looking like

function(doc) {

... lots of js library code ...

blah blah...

emit(key, value)

}

this is good because you want the view to be erased if you change the
code that generates it.

On Thu, Nov 20, 2008 at 6:36 AM, Kerr Rainey <ke...@rokera.com> wrote:
>> I would make your own .js file that includes your libraries and main.js,
>> then add that as a custom view server in local.ini. Then upgrades won't
>> break it. That's elegant enough for me.
>
> but then you wouldn't be able to replicate the design around.
>
> --
> Kerr
>



-- 
Chris Anderson
http://jchris.mfdz.com

Re: Adding JS Libraries for Views?

Posted by Kerr Rainey <ke...@rokera.com>.
> I would make your own .js file that includes your libraries and main.js,
> then add that as a custom view server in local.ini. Then upgrades won't
> break it. That's elegant enough for me.

but then you wouldn't be able to replicate the design around.

--
Kerr

Re: Adding JS Libraries for Views?

Posted by Anthony Eden <an...@gmail.com>.
On Thu, Nov 20, 2008 at 9:03 AM, Jedediah Smith
<je...@silencegreys.com> wrote:
>
> I would make your own .js file that includes your libraries and main.js,
> then add that as a custom view server in local.ini. Then upgrades won't
> break it. That's elegant enough for me.

When you say "includes" do you mean that my own JS file would actually
have main.js along with all of the required library code in a single
text file?

Sincerely,
Anthony Eden

Re: Adding JS Libraries for Views?

Posted by Jedediah Smith <je...@silencegreys.com>.
I would make your own .js file that includes your libraries and main.js, 
then add that as a custom view server in local.ini. Then upgrades won't 
break it. That's elegant enough for me.

Anthony Eden wrote:
> What is the best way to add JavaScript libraries to CouchDB so that
> they may be used in JavaScript views?
> 
> I was thinking of somehow adding libraries to
> /usr/local/share/couchdb/server/main.js however I'm reluctant to just
> jump straight into doing this since it seems like a brute force way to
> solve a problem that must be better accomplished with a more elegant
> solution.
> 
> Any suggestions?
> 
> Thanks!
> 
> Sincerely,
> Anthony Eden
> 

Re: Adding JS Libraries for Views?

Posted by Kerr Rainey <ke...@rokera.com>.
> Putting code in main.js is definitely less-than ideal - I'd
> prefer to be able to install JavaScript code into CouchDB as a
> document and have it be reusable across my views.

Yes, that would be very nice.

--
Kerr

Re: Adding JS Libraries for Views?

Posted by Anthony Eden <an...@gmail.com>.
On Thu, Nov 20, 2008 at 8:30 AM, Benoit Chesneau <bc...@gmail.com> wrote:
> On Thu, Nov 20, 2008 at 1:09 PM, Anthony Eden <an...@gmail.com> wrote:
>> What is the best way to add JavaScript libraries to CouchDB so that
>> they may be used in JavaScript views?
>>
>> I was thinking of somehow adding libraries to
>> /usr/local/share/couchdb/server/main.js however I'm reluctant to just
>> jump straight into doing this since it seems like a brute force way to
>> solve a problem that must be better accomplished with a more elegant
>> solution.
>>
>> Any suggestions?
>>
>> Thanks!
>>
>> Sincerely,
>> Anthony Eden
>>
>
> why would you like that ?

My current use case is to allow my views to access the DateJS library.
Ideally what I would like to have would be a way to expose custom JS
libraries across all of my views without needing to include it in each
view. Putting code in main.js is definitely less-than ideal - I'd
prefer to be able to install JavaScript code into CouchDB as a
document and have it be reusable across my views.

Sincerely,
Anthony Eden

Re: Adding JS Libraries for Views?

Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Nov 20, 2008 at 1:09 PM, Anthony Eden <an...@gmail.com> wrote:
> What is the best way to add JavaScript libraries to CouchDB so that
> they may be used in JavaScript views?
>
> I was thinking of somehow adding libraries to
> /usr/local/share/couchdb/server/main.js however I'm reluctant to just
> jump straight into doing this since it seems like a brute force way to
> solve a problem that must be better accomplished with a more elegant
> solution.
>
> Any suggestions?
>
> Thanks!
>
> Sincerely,
> Anthony Eden
>

why would you like that ?

- benoƮt