I am very new to js. I want to insert values into my error table, such as timestamp and type of error returned in node js. My current node js code inserts values into database but I want something in error block. Below is my node.js code.
var pg = require('pg');
var transaction = require('pg-transaction');
var die = function(err){
if (err) throw err;
};
exports.handler = function(event, context) {
var pgClient = new pg.Client({
user: 'XXXX',
database: 'XXXX',
password: 'XXXX',
port: 5439,
host: "XXXXX"
});
pgClient.connect();
var tx = new transaction(pgClient);
tx.on('error',die);
tx.begin();
tx.query("truncate table tbl;");
tx.query("insert into tbl..................;");
tx.query("select * from tbl",function(err,result) {
console.log("XXXX: "+JSON.stringify(result));
});
tx.query("truncate table;");
tx.commit(function(){
pgClient.end(function(err) {
if(err) throw err;
console.log("Successful");
});
});
};
Insert into error_log(select getdate(),error_type);
So, where do I write my sql?