1

There are a number of functions I want to use across various couchdb view map functions. I am trying to use the commonjs require pattern.

Using the following design doc why does the test1 require statement work whereas the test2 require statement does not seem to work ?

How else can I reuse functions across multiple couchdb views ?

{
    "_id": "_design/app",
    "_rev": "29-876296b1278db067378635a5f3309aa3",
    "views": {
       "test1": {
           "map": "function (doc) {\n  var setting1 = require('views/lib/config').setting1;\n    emit(doc._id, setting1);\n  }"
       },
       "test2": {
           "map": "function (doc) {\n  var fn1 = require('views/lib/sharedFunctions').fn1;\n    emit(doc._id, fn1(doc));\n  }"
       },
       "lib": {
           "config": "exports.setting1 = 'a';exports.setting2 = 42",
           "sharedFunctions":"exports.fn1 = function (doc) {\n   return 'fn1 read doc ' + doc._id;\n }"
       }
    }
}

further info: I am currently using the 'grunt-couchapp' plugin for managing the uploading of my design docs from my project src directories

johowie
  • 2,475
  • 6
  • 26
  • 42
  • What's the output of test2? What's your CouchDB version? Both views are works for me for 1.2.2 and 1.3.0 releases. Debug logs are also welcome and may help a bit to understand the problem. – Kxepal Jun 23 '13 at 17:49
  • couchdb v1.2.0, I'll update and see how I go, if still probs I'll post debug logs – johowie Jun 25 '13 at 03:27
  • 1
    all working on v1.3.1 . I haven't tried any earlier versions. So it seems that the requiring of functions wasn't working in v1.2.0 – johowie Jun 27 '13 at 07:17

1 Answers1

1

Just adding this as the answer so that this question stops appearing unanswered. The OP found that upgrading to 1.3 (from 1.2) fixed the problem.

smathy
  • 26,283
  • 5
  • 48
  • 68