Skip to content

Instantly share code, notes, and snippets.

@tobie
Created June 30, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobie/57c0b3c28ec7ceadb157 to your computer and use it in GitHub Desktop.
Save tobie/57c0b3c28ec7ceadb157 to your computer and use it in GitHub Desktop.
CouchDB design doc
module.exports = {
_id: "_design/xxx",
views: {
by_date: {
map: function(doc) {
var parts = doc._id.split(":");
emit(parts, { shortname: parts[0], date: parts[1] });
}
},
updates_by_date: {
map: function(doc) {
if (doc.aliasOf) return;
var parts = doc._id.split(":");
emit(parts, { shortname: parts[0], date: parts[1] });
}
}
}
};
"use strict";
require("../env");
var fs = require("fs");
var path = require("path");
var async = require("async");
var client = require("../lib/couch-client")();
var dir = path.join("lib", "_design");
fs.readdir(dir, function (err, files) {
if (err) throw err;
async.map(files, function(f, callback) {
f = "_design/" + path.basename(f, ".js");
client.insert(require("../lib/" + f), f, callback);
}, console.log.bind(console));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment