this article gives an example of the method that Node.js implements an automatic recovery connection using a transaction in a MySQL connection pool. Share to you for your reference, as follows:

 var MySQL ('mysql') = require, Connection = require ('mysql/lib/Connection.js'); VAR pool = mysql.createPool (database:'myDB','127.0.0.1' {host:, port: 3306, user:'root', password:'root', debug: false, connectionLimit: var execPool;} 3) = {pool.getConnection (function) (function (err, Conn) {transAutoRelease (conn); conn.beginTransaction (function (ERR) {if (ERR throw ERR); conn.query ("INSERT INTO test (ID, name, date, test) values (1,'123', now), (1), function (err, RET) {if (ERR) {console.error (ERR); conn.rollback (function () {});} else {console.log (RET; conn.query ('U) PDATE test set id=12321312 where id=1'function (err, RET) {if (ERR) {console.error (ERR); conn.rollback (function () {}} {(conn.commit); else (function) {console.log ('success' + JSON.stringify (RET));}}});}});}););}}); function after (FN, CB) {return (function) {fn.apply (this, arguments); (CB);}} function {transAutoRelease (conn) if (conn.commit = = Connection.prototype.commit) conn.commit = after (conn.commit, release); if (conn.rollback = = Connection.prototype.rollback conn.rollback = after (conn.rollback) function relea, release); (SE) if (conn) {{}}} (conn.release); VAR (intervalStartProcess = function) {setInterval (function) (execPool);}, {(1000)}; for (VaR I = 5-1; I = 0; > i--) {(intervalStartProcess)}; 

hope in this paper, the design of nodejs program to help you.

This paper fixed link:http://www.script-home.com/node-js-example-of-a-method-to-implement-a-transaction-automatically-reclaim-connection-for-a-mysql-connection-pool.html | Script Home | +Copy Link

Article reprint please specify:Node.js example of a method to implement a transaction automatically reclaim connection for a MySQL connection pool | Script Home

You may also be interested in these articles!