2
var ddoc = {
  _id: '_design/app',
  language: 'javascript',
  views: {},
  lists: {},
  shows: {},
  lib: {/* see below */}
};

I can't find good documentation about what to put into ddoc.lib, eg:

  1. Can I put functions: ddoc.lib.myHelper = function () {}; ?
  2. Can I reference JavaScript files (CommonJS module?): ddoc.lib.math = 'math.js';

In case of 2. where to store math.js?

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
abernier
  • 27,030
  • 20
  • 83
  • 114
  • 1
    Take a look at all answers to this question: [How do I DRY up my CouchDB views?][1] [1]: http://stackoverflow.com/questions/1197449/how-do-i-dry-up-my-couchdb-views – Davorin Ruševljan Oct 11 '12 at 06:55
  • @DavorinRuševljan: you are my answer! Particularly interesting article following your link: http://caolanmcmahon.com/posts/commonjs_modules_in_couchdb/ Post an answer with it and you'll have the green tick ;) – abernier Oct 19 '12 at 01:28
  • I have actually done that at first, but StackOverflow software decided it is too simple and auto converted it to comment above! :) so I will leave it at that. Thanks anyway! – Davorin Ruševljan Oct 19 '12 at 08:56

2 Answers2

0

As far as I know the best solution for today is to use couchapp. It can create a sceleton that could be edited easily.

Anthony
  • 12,407
  • 12
  • 64
  • 88
  • I already use couchapp (node-couchapp in my case) but I can't find any documentation about the `ddoc.lib` object... – abernier Oct 10 '12 at 15:13
0

The best couchapp manager I have seen is http://kan.so/ I would just use this, but ...

To roughly answer your questions.

  1. yes you can put functions in lib, but they must be turned into escaped strings. You want to just put them in like you would a file though not an anonymous function.
  2. yes you can require just structure as

    "lib": { "math.js":"escaped source" }

Hatchware
  • 242
  • 2
  • 13