Db Change. Moved the database from local to cloudant

This commit is contained in:
Martin Donnelly 2016-12-22 09:31:08 +00:00
parent a216191c14
commit c4b79ea932
2 changed files with 49 additions and 13 deletions

View File

@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"body-parser": "^1.15.0", "body-parser": "^1.15.0",
"cheerio": "^0.20.0", "cheerio": "^0.20.0",
"cloudant": "^1.6.2",
"cookie-parser": "^1.4.1", "cookie-parser": "^1.4.1",
"ejs": "^2.4.1", "ejs": "^2.4.1",
"express": "^4.13.4", "express": "^4.13.4",

View File

@ -17,11 +17,35 @@ var router = express.Router();
var EventEmitter = require('events'); var EventEmitter = require('events');
var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984'); //var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984');
var busEmitter = new EventEmitter(); var busEmitter = new EventEmitter();
var db_name = 'keeper'; var db_name = 'keeper';
var dbCouch = nano.use(db_name); //var dbCouch = nano.use(db_name);
/*
We've moved to cloudant through IBM Bluemix for the database
https://25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix.cloudant.com/dashboard.html#usage
*/
var credentials = {
"username": "25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix",
"password": "8e417af1b0462ca55726848846cc6b8696fc76defe9d1864cbc334be59549e0c",
"host": "25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix.cloudant.com",
"port": 443,
"url": "https://25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix:8e417af1b0462ca55726848846cc6b8696fc76defe9d1864cbc334be59549e0c@25f854ee-1b51-49ff-acd9-5b0ff478d944-bluemix.cloudant.com",
"database" : "keeper"
};
var Cloudant = require('cloudant');
var cloudant = Cloudant({account:credentials.username, password:credentials.password});
var dbCloudant = cloudant.db.use(credentials.database);
var jsonFile = __dirname + '/' + 'output.json'; var jsonFile = __dirname + '/' + 'output.json';
var bodyfile = __dirname + '/' + 'body.html'; var bodyfile = __dirname + '/' + 'body.html';
@ -103,7 +127,8 @@ function cleaner(b) {
function insertBookmark(obj) { function insertBookmark(obj) {
logger.debug('Inserting into couch...'); logger.debug('Inserting into couch...');
logger.info(util.inspect(obj)); logger.info(util.inspect(obj));
dbCouch.insert(obj, function(err, body, header) { // dbCouch.insert(obj, function(err, body, header) {
dbCloudant.insert(obj, function(err, body, header) {
if (err) { if (err) {
logger.error('Error inserting into couch'); logger.error('Error inserting into couch');
return; return;
@ -118,7 +143,8 @@ function updateBookmark(obj, _id, _rev) {
_obj._id = _id; _obj._id = _id;
_obj._rev = _rev; _obj._rev = _rev;
dbCouch.insert(_obj, function(err, body, header) { //dbCouch.insert(_obj, function(err, body, header) {
dbCloudant.insert(_obj, function(err, body, header) {
if (err) { if (err) {
logger.error('Error updating into couch'); logger.error('Error updating into couch');
return; return;
@ -159,7 +185,8 @@ var doGetBookmarkRes = (url, res) => {
var doUpdateTagsDB = () => { var doUpdateTagsDB = () => {
logger.debug('Update the tags database...'); logger.debug('Update the tags database...');
dbCouch.view('getAllTags', 'getAllTags', function(err, body) { // dbCouch.view('getAllTags', 'getAllTags', function(err, body) {
dbCloudant.view('getAllTags', 'getAllTags', function(err, body) {
var masterList = []; var masterList = [];
if (!err) { if (!err) {
body.rows.forEach(function(doc) { body.rows.forEach(function(doc) {
@ -171,7 +198,8 @@ var doUpdateTagsDB = () => {
return self.indexOf(value) === index; return self.indexOf(value) === index;
}); });
dbCouch.view('taglist', 'taglist', function(err, body) { //dbCouch.view('taglist', 'taglist', function(err, body) {
dbCloudant.view('taglist', 'taglist', function(err, body) {
// Logger.debug(body); // Logger.debug(body);
if (!err) { if (!err) {
@ -200,7 +228,8 @@ var doSaveTagsDB = (orig, newList) => {
_obj.taglist = newList; _obj.taglist = newList;
dbCouch.insert(_obj, function(err, body, header) { //dbCouch.insert(_obj, function(err, body, header) {
dbCloudant.insert(_obj, function(err, body, header) {
if (err) { if (err) {
logger.error('Error updating into couch'); logger.error('Error updating into couch');
return; return;
@ -552,7 +581,8 @@ router.get('/pocket', function(req, res) {
logger.debug('list..'); logger.debug('list..');
dbCouch.view('pocketList', 'pocketList', function(err, body) { // dbCouch.view('pocketList', 'pocketList', function(err, body) {
dbCloudant.view('pocketList', 'pocketList', function(err, body) {
if (!err) { if (!err) {
var outJSON = []; var outJSON = [];
@ -586,7 +616,8 @@ router.get('/pocket', function(req, res) {
router.get('/list', function(req, res) { router.get('/list', function(req, res) {
logger.debug('list..'); logger.debug('list..');
dbCouch.view('titles', 'titles', function(err, body) { //dbCouch.view('titles', 'titles', function(err, body) {
dbCloudant.view('titles', 'titles', function(err, body) {
if (!err) { if (!err) {
var outJSON = []; var outJSON = [];
@ -610,7 +641,8 @@ router.get('/entry/:id', function(req, res) {
logger.debug(req.params.id); logger.debug(req.params.id);
dbCouch.get(req.params.id, function(err, body) { //dbCouch.get(req.params.id, function(err, body) {
dbCloudant.get(req.params.id, function(err, body) {
if (!err) { if (!err) {
var outJSON = {}; var outJSON = {};
@ -639,7 +671,8 @@ router.route('/tags')
logger.debug(req.params.id); logger.debug(req.params.id);
dbCouch.view('taglist', 'taglist', function(err, body) { //dbCouch.view('taglist', 'taglist', function(err, body) {
dbCloudant.view('taglist', 'taglist', function(err, body) {
if (!err) { if (!err) {
logger.debug(body); logger.debug(body);
var outJSON = []; var outJSON = [];
@ -667,7 +700,8 @@ router.route('/tags')
logger.info('regetting:' + req.body._id); logger.info('regetting:' + req.body._id);
dbCouch.get(req.body._id, function(err, body) { //dbCouch.get(req.body._id, function(err, body) {
dbCloudant.get(req.body._id, function(err, body) {
if (!err) { if (!err) {
var obj = {}; var obj = {};
@ -707,7 +741,8 @@ router.get('/tags/:id', function(req, res) {
logger.debug(req.params.id); logger.debug(req.params.id);
dbCouch.view('getTagByKey', 'getTagByKey', function(err, body) { //dbCouch.view('getTagByKey', 'getTagByKey', function(err, body) {
dbCloudant.view('getTagByKey', 'getTagByKey', function(err, body) {
if (!err) { if (!err) {
// Logger.debug(body); // Logger.debug(body);
var outJSON = []; var outJSON = [];