Skip to content

Instantly share code, notes, and snippets.

@leonguyen
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save leonguyen/ece705456036f8cc27e1 to your computer and use it in GitHub Desktop.

Select an option

Save leonguyen/ece705456036f8cc27e1 to your computer and use it in GitHub Desktop.
Transactions
conn.beginTransaction(function(err) {
if (err) {
throw err;
}
conn.query('INSERT INTO gluer_topic SET ?', data, function(err, result) {
if (err) {
console.error(err);
conn.rollback(function() {
throw err;
});
}
var data1 = {
UID: uid,
TID: result.insertId,
UTAuthority: 'C',
UTAccess: 'RWVC'
};
console.log('[createTopic] data:' + data1);
conn.query('INSERT INTO gluer_ut SET ? ', data1, function(err, result1){
if(err) {
console.error(err);
conn.rollback(function() {
throw err;
});
return next(err, -1);
}
conn.commit(function(err) {
if (err) {
conn.rollback(function() {
throw err;
});
}
console.log('[createTopic] Create Topic OK');
return next(false, result.insertId);
});//Commit
});//gluer_ut
});//gluer_topic
});//Transaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment