forked from twilson63/express-couchUser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
30 lines (28 loc) · 783 Bytes
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// the purpose of this script
// is to create a couch db design doc
// and view for the model list functionality
var nano = require('nano');
var userView = require('./lib/user');
module.exports = init = function(couch, cb) {
var db = nano(couch);
db.get('_design/user', function(err, doc) {
if (!doc || userView.version > doc.version) {
if (doc) { userView._rev = doc._rev; }
db.insert(userView,'_design/user', function(err, body) {
if (err) {
console.log(err);
if (cb) { cb(err); }
}
if (!module.parent) { console.log(body); }
if (cb) { cb(null); }
});
}
});
}
if (!module.parent) {
if (process.argv[2]) {
init(process.argv[2]);
} else {
console.log('couchdb url required');
}
}