keeper/server/viewinsert.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-03-21 16:27:14 +00:00
var nano = require('nano')('http://localhost:5984');
var db_name = 'keeper';
var keeper = nano.use(db_name);
keeper.insert(
{
"views": {
"taglist": {
2016-03-21 16:40:15 +00:00
"map": function (doc) { if (doc.type == 1) { emit(null, doc); } }
2016-03-21 16:27:14 +00:00
}
}
}, '_design/taglist', function (error, response) {
2016-03-21 16:40:15 +00:00
if (error) {
console.log(error);
} else
{
console.log("_design/taglist added");
}
2016-03-21 16:27:14 +00:00
});
keeper.insert(
{
"views": {
"getAllTags": {
2016-03-21 16:40:15 +00:00
"map": function (doc) { if (doc.tags.list.length > 0) { emit(null, doc.tags.list); } }
2016-03-21 16:27:14 +00:00
}
}
}, '_design/getAllTags', function (error, response) {
2016-03-21 16:40:15 +00:00
if (error) {
console.log(error);
} else
{
console.log("_design/getAllTags added");
}
2016-03-21 16:27:14 +00:00
});
2016-03-21 16:40:15 +00:00
2016-03-21 16:27:14 +00:00
keeper.insert(
{
"views": {
2016-03-21 16:40:15 +00:00
"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]); } } }
2016-03-21 16:27:14 +00:00
}
}
2016-03-21 16:40:15 +00:00
}, '_design/getTagByKey', function (error, response) {
if (error) {
console.log(error);
} else
{
console.log("_design/getTagByKey added");
}
2016-03-21 16:27:14 +00:00
2016-03-21 16:40:15 +00:00
});