[nodeJS]mysql.pool must release connection

2015-9-17 写技术

/*

In nodejs.

While processing database by pool, don't forget release the connection.

*/

               var pool = app.mysql.pool;

                pool.getConnection(function(err, con){
                        if(err){
                                throw(err);
                        }
                        var table = web_data.table;
                        var _data = web_data.datas;
                        var map = web_data.map;

                        var query = 'update '+table+' set '+ _data +' where '+ map ;
                        console.log(query);
                        con.query(query, function(err, ret){
                                pool.releaseConnection(con);
                                if(err){
                                        throw(err);
                                }
                                return ret;
                        });
                });

标签: nodeJS

发表评论:

Powered by anycle 湘ICP备15001973号-1