node.js - Dealing with MySql pooling and nodejs -
i run web server written in nodejs/ express deals mysql db. in order more efficient, use pooling mechanism of node-mysql.
an still issues : - connection lost - cannot release release connection - there no release of undefined
depending on request, various code pattern can used data , release connection :
1/ standard callback ...,function(err, rows){...}
- may understood, release shall done before callback ? please confirm me ! - may use release @ first line of call function ? (because may have many case in case various callback.
2/ event - put connection.release in both events .on('error')
, .on('end')
. enough ? - happen if error called on 10th rows. both event called ? think not, got issue (can,not release release connection) following code :
pool.getconnection(function(err, mysqlconnection) { if (err != null) { console.log(err); } else { mysqlconnection.query('use table'); var xs = new array(); if (selectedb === 'b') { if (selectedc === 'c') { var querycmd = "select distinct nom x ='" + selecteda + "'"; var query = mysqlconnection.query(querycmd); query // error .on('error', function(err) { mysqlconnection.release(); }) // result .on('result', function(row) { mysqlconnection.pause(); var x = row['nom']; xs.push(x); mysqlconnection.resume(); }) // end .on('end', function() { mysqlconnection.release(); callback(xs); }) } else { mysqlconnection.release(); callback([]); } } else { mysqlconnection.release(); callback([]); } } });
3/ return - call release before return !
then, there snippets error handling standard connection, should connection pooling ? cause in case, crash server !
thanks in advance advises. definitively me lot !
Comments
Post a Comment