couchdb-utils

CouchDB utils

couchdb-utils

Management of versioning and updates of couchdb design documents is based on grave project.

var cradle = require('cradle'),
    cutils = require('couchdb-utils');

var db = new (cradle.Connection)().database('my-database');
var design = new cutils.Design(db, 'my-view', '0.0.2');

design.view('all', {
    map : function (doc) {
        if (doc.type === 'my-doc') emit(doc._id, 1);
    },
});

design.end(function(err) {
    console.log('all views are up-to-date');
});

Design views, lists and updates

Start a design with a name and a version. Theversion should be understood by semver.

Define a couchdb view. CouchDB views have map, reduce, and fields of that sort.

Define a couchdb list. CouchDB lists are functions that look like function (head, req) { /* ... */ }.

Define a couchdb update. These look like function (doc, req) { /* ... */ }.

Declare the end of the design document definitions and save them to couchdb when the design version is greater than the couchdb version.