update couch builder

This commit is contained in:
martind2000 2016-03-21 22:27:51 +00:00
parent cf09ad072c
commit 3d7770b294
2 changed files with 89 additions and 153 deletions

View File

@ -38,39 +38,7 @@ nano.db.destroy('keeper', function () {
console.log("_design/reducedView added");
});
keeper.insert(
{
"views": {
"taglist": {
"map": function (doc) { if (doc.type == 1) { emit(null, doc); } }
}}
}, '_design/taglist', function (error, response) {
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) {
console.log("_design/getAllTags added");
});
keeper.insert(
{
"views": {
"getAllTags": {
"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) {
console.log("_design/getTagByKey added");
});
});
});

View File

@ -1,143 +1,111 @@
var nano = require('nano')('http://localhost:5984');
var logger = require('log4js').getLogger();
var db_name = 'keeper';
var keeper = nano.use(db_name);
keeper.destroy('_design/titles', function(err, body) {
if (error) {
console.log(error);
} else
{
console.log('titles deleted');
keeper.insert(
{
"views": {
"titles": {
"map": function (doc) { emit(null, doc.title); }
}
}
}, '_design/titles', function (error, response) {
if (error) {
console.log(error);
} else
{
console.log('remade : ' + _design/titles);
console.log(response);
}
});
var tableList = [
{
name: '_design/titles', view: {
"titles": {
"map": function(doc) { emit(null, doc.title); }
}
});
}
}
/*
keeper.destroy('_design/reducedView', function(err, body) {
if (error) {
console.log(error);
} else
{
console.log('deleted');
console.log(body);
, {
name: '_design/reducedView', view: {
"reducedView": {
"map": function(doc) { emit(null, [doc.title, doc.reduced]); }
}
}
});
keeper.destroy('_design/taglist', function(err, body) {
if (error) {
console.log(error);
} else
{
console.log('deleted');
console.log(body);
}, {
name: '_design/taglist', view: {
"map": function(doc) { if (doc.type == 1) { emit(null, doc); } }
}
});
keeper.destroy('_design/getAllTags', function(err, body) {
if (error) {
console.log(error);
} else
{
console.log('deleted');
console.log(body);
}, {
name: '_design/getAllTags', view: {
"map": function(doc) {
if (doc.tags.list.length > 0) {
emit(null, doc.tags.list);
}
}
}
});
keeper.destroy('_design/getTagByKey', function(err, body) {
if (error) {
console.log(error);
} else
{
console.log('deleted');
console.log(body);
}, {
name: '_design/getTagByKey', view: {
"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]);
}
}
}
}
});
}
];
var killTable = (table) =>
{
console.log(table.name);
keeper.get(table.name, {revs_info: true}, function(err, body) {
if (err)
console.log(err);
if (typeof body !== 'undefined') {
keeper.insert(
{
"views": {
"reducedView": {
"map": function (doc) { emit(null, [doc.title, doc.reduced]); }
keeper.destroy(table.name, body._rev, function(_err, _body) {
if (err) {
console.log(_err);
}
else {
console.log(table.name + ' deleted');
console.log(_body);
}
});
}
});
};
var updateTable = (table) =>
{
logger.info(table.name);
keeper.get(table.name, {revs_info: true}, function(err, body) {
if (err)
logger.error(body);
if (typeof body !== 'undefined') {
keeper.insert({_id: body._id, _rev: body._rev, views: table.view},
function(_err, _body) {
if (err) {
logger.error(_err);
}
}
}, '_design/reducedView', function (error, response) {
if (error) {
console.log(error);
} else
{
console.log(response);
}
});
else {
logger.info(table.name + ' updated');
logger.info(_body);
keeper.insert(
{
"views": {
"taglist": {
"map": function (doc) { if (doc.type == 1) { emit(null, doc); } }
}
}
}, '_design/taglist', function (error, response) {
});
}
else {
keeper.insert({
"views": table.view
}, table.name, function(error, response) {
if (error) {
console.log(error);
} else
{
console.log(response);
logger.error(error);
}
});
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(response);
else {
logger.info(response);
}
});
}
});
});
};
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(response);
}
});*/
for (var t = 0; t < tableList.length; t++) {
updateTable(tableList[t]);
}