-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.node.js
63 lines (51 loc) · 1.52 KB
/
setup.node.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
creating db structure, other setup and configuration stuff
*/
var nano = require('nano')('http://localhost:5984');
var secrets = require("./secrets.js").secrets();
var db_name = secrets.db_name;
var db = nano.use(db_name);
console.log("db_name " + db_name);
var design = {};
// set up db:
db.get("_design/" + db_name, function(err, body){
if(err){
console.log("error getting design");
console.log(err);
db.insert(design,
function (error,http_body,http_headers) {
if(error) {
if(error.message === 'no_db_file') {
// create database and retry
return nano.db.create(db_name, function () {
console.log("created");
});
}
else { return console.log(error); }
}
console.log(http_body);
});
}else{
console.log("got design, going to destroy " + body);
db.destroy(body._id, body._rev, function(err2, body2){
if(err){
console.log("error destroying design");
console.log(err);
}else{
db.insert(design,
function (error,http_body,http_headers) {
if(error) {
if(error.message === 'no_db_file') {
// create database and retry
return nano.db.create(db_name, function () {
console.log("created");
});
}
else { return console.log(error); }
}
console.log(http_body);
});
}
});
}
});