Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs mysql transactions

connection.beginTransaction(function(err) {
  if (err) { throw err; }
  connection.query('INSERT INTO posts SET title=?', title, function (error, results, fields) {
    if (error) {
      return connection.rollback(function() {
        throw error;
      });
    }
 
    var log = 'Post ' + results.insertId + ' added';
 
    connection.query('INSERT INTO log SET data=?', log, function (error, results, fields) {
      if (error) {
        return connection.rollback(function() {
          throw error;
        });
      }
      connection.commit(function(err) {
        if (err) {
          return connection.rollback(function() {
            throw err;
          });
        }
        console.log('success!');
      });
    });
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: words counter in javascript 
Javascript :: percentage with react 
Javascript :: the filter array 
Javascript :: mongoose express js post 
Javascript :: await javascript 
Javascript :: window.addeventlistener multiple events 
Javascript :: javascript add field to array 
Javascript :: why to use arrow functions over normal function 
Javascript :: javascript Symbol Methods 
Javascript :: iframe content zoom in and zoom out jquery 
Javascript :: defined variables if null javascript 
Javascript :: axios 400 bad request 
Javascript :: how to update react app 
Javascript :: typescript jsdoc interface 
Javascript :: es6 spread assign nested object 
Javascript :: document.ready javascript 
Javascript :: display fetch response js 
Javascript :: three js html 
Javascript :: $(...).DataTable is not a function 
Javascript :: javascript github 
Javascript :: how to async javascript stack overflow 
Javascript :: every element in list after first javascript 
Javascript :: text slider in react js 
Javascript :: addeventlistener js 
Javascript :: window parent frames javascript 
Javascript :: send request express 
Javascript :: how to calculate first monday of the month in js 
Javascript :: crud operation react js 
Javascript :: Remove all falsy values from an array 
Javascript :: how to select a dom element in react 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =