For development, I want to keep the various components (views
, lists
, shows
) that make up a couchDB design document as separate files alongside my other development code in a dir called couchDB for example.
When I am happy with changes I want to use couchapp.push to send to database, whilst also being able to version control the design doc component files.
I'm thinking maybe using the node module 'couchapp' and node to scan a directory and its sub-dirs for .js files then using them to construct the design docs and upload to couchDB. Perhaps with sub dirs structured like so:
designDocsJs
|-- views
| |--view1.js
| |--view2.js
|-- shows
|-- lists
Is it possible to put map and reduce in the same file eg. 'view1.js'
or would they need to be in separate files 'view1-map.js'
and 'view1-reduce.js'
?
Curretnly I am using the following, but I am not sure how to go about reading the .js files using node and dynamically adding them to the ddoc.views{} ? Any guidance would be appreciated, particularly with a javascript/node solution.
var couchapp = require('couchapp')
, path = require('path');
ddoc = {
_id: '_design/entitiesNew'
, views: {}
, lists: {}
, shows: {}
}
// node module exports
module.exports = ddoc;
// REPLACE ME WITH SOME WAY OF READING A
// STRUCTURED DIR OF .JS FILES AND COMBINING
// AS NECESSARY
ddoc.views.byType = {
map: function(doc) {
emit(doc.type, null);
},
reduce: '_count'
}
couchapp.loadAttachments(ddoc, path.join(__dirname, '_attachments'));
and then:
$ cd path/to/here
$ mkdir _attachments
$ couchapp push updateCouchDbDesigndocs.js http://localhost:5984/databaseName