Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Use SQL transactions with node-mysql
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
history.md
index.js
license.md
package.json
readme.md

readme.md

node-mysql-transactions

dependencies

npm install mysql

install

npm install mysql-transactions

quick start

var transactions = require('mysql-transactions')({
    user: 'hamburglar',
    password: 'omnomnomnomnomnom',
    database: 'playhouse'
});



transactions.begin();


transactions.query('INSERT INTO users SET ?', { name: 'Lord Voldemort' }, function(err, result) {

    if (err) {
        transactions.rollback();
        return console.log('Rolled back.');
    }


    transactions.commit(function(err, result) {
        console.log('Committed.');
    });

});

Note: After calling .begin(), .commit() or .rollback() must be called so that the connection is closed.

api

Each [fn] is a callback for a mysql.query.

  • begin([fn]): start the transaction process.
  • query(String [, Object/Array] [, fn]): traditional query.
  • rollback([fn]): rollback the transaction.
  • commit([fn]): commit the transaction.
Something went wrong with that request. Please try again.