samedi 4 avril 2015

Cannot insert record to PostgreSQL in Bluemix

I try to get postgresql work with Node.js in Bluemix platform. However, there is a problem. I tried to use the code described in http://ift.tt/1bVCHSd.


I can run the app I written successfully in local environment. However, it is not functioning properly in Bluemix platform.


Following is the code describing what I have done:



var recordVisit = function(req, res) {
/* Connect to the DB and auth */
pg.connect(psql,
function(err, client, done) {
if (err) {
return console.error('Error requesting client', err);
}

console.log(req.ip);

client.query('insert into ips(ip, ts) values($1, $2)', [req.ip, new Date()],
function(err, result) {
if (err) {
done();
return console.error('Error inserting ip', err);
}

client.query('select count(ip) as count from ips where ip=$1',
[req.ip],
function(err, result) {
done();
if (err) {
return console.error('Error querying count', err);
}
console.log("You have visited " + result.rows[0].count + " times")
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.end();
}
);
}
);
}
);
};


It is following the code from the bluemix document. The result of the visit count in Bluemix always be zero (0). But the result in local environment is okay. And I did not get any error from the Bluemix platform. So I assume that the visit record can be inserted. However, seems that it is not.


Can anyone have any pointer for me to solve this problem?


Aucun commentaire:

Enregistrer un commentaire