Please guide me how to perform transaction management in sqlite3 using expressjs. I tried in this way but am not succeed.
app.get('/transaction', function(req, res){ db.serialize(function() { try{ db.run("BEGIN"); db.run("UPDATE emp SET balance = 10000 WHERE eid = 1", function(err, row){ if (err){ throw (e); } }); db.run("UPDATE temp SET deptno = 2000 WHERE eid = 2", function(err, row){ //this temp table not exists it should be rollback and server should not //stop if (err){ throw (e); } }); db.run('commit'); res.end("Transaction succeed"); }//try catch(e){ //console.log(e); res.end("Transaction cancelled"); db.run('rollback'); //console.log(e); }//catch });
});