102 lines
2.4 KiB
JavaScript
102 lines
2.4 KiB
JavaScript
var nano = require('nano')('http://localhost:5984');
|
|
|
|
var db_name = 'keeper';
|
|
var keeper = nano.use(db_name);
|
|
|
|
alice.destroy('_design/titles', function(err, body) {
|
|
if (!err)
|
|
console.log(body);
|
|
});
|
|
alice.destroy('_design/reducedView', function(err, body) {
|
|
if (!err)
|
|
console.log(body);
|
|
});
|
|
alice.destroy('_design/taglist', function(err, body) {
|
|
if (!err)
|
|
console.log(body);
|
|
});
|
|
alice.destroy('_design/getAllTags', function(err, body) {
|
|
if (!err)
|
|
console.log(body);
|
|
});
|
|
alice.destroy('_design/getTagByKey', function(err, body) {
|
|
if (!err)
|
|
console.log(body);
|
|
});
|
|
|
|
keeper.insert(
|
|
{
|
|
"views": {
|
|
"titles": {
|
|
"map": function (doc) { emit(null, doc.title); }
|
|
}
|
|
}
|
|
}, '_design/titles', function (error, response) {
|
|
console.log("_design/titles added");
|
|
});
|
|
|
|
keeper.insert(
|
|
{
|
|
"views": {
|
|
"reducedView": {
|
|
"map": function (doc) { emit(null, [doc.title, doc.reduced]); }
|
|
}
|
|
}
|
|
}, '_design/reducedView', function (error, response) {
|
|
console.log("_design/reducedView added");
|
|
});
|
|
|
|
|
|
|
|
keeper.insert(
|
|
{
|
|
"views": {
|
|
"taglist": {
|
|
"map": function (doc) { if (doc.type == 1) { emit(null, doc); } }
|
|
}
|
|
}
|
|
}, '_design/taglist', function (error, response) {
|
|
if (error) {
|
|
console.log(error);
|
|
} else
|
|
{
|
|
console.log("_design/taglist added");
|
|
}
|
|
|
|
});
|
|
|
|
keeper.insert(
|
|
{
|
|
"views": {
|
|
"getAllTags": {
|
|
"map": function (doc) { if (doc.tags.list.length > 0) { emit(null, doc.tags.list); } }
|
|
}
|
|
}
|
|
}, '_design/getAllTags', function (error, response) {
|
|
if (error) {
|
|
console.log(error);
|
|
} else
|
|
{
|
|
console.log("_design/getAllTags added");
|
|
}
|
|
|
|
});
|
|
|
|
|
|
keeper.insert(
|
|
{
|
|
"views": {
|
|
"getTagByKey": {
|
|
"map": function (doc) { if (doc.tags.list.length > 0) { for (var t = 0; t < doc.tags.list.length; t++) { emit(doc._id, [doc.tags.list[t], doc.title]); } } }
|
|
}
|
|
}
|
|
}, '_design/getTagByKey', function (error, response) {
|
|
if (error) {
|
|
console.log(error);
|
|
} else
|
|
{
|
|
console.log("_design/getTagByKey added");
|
|
}
|
|
|
|
});
|