mysql-pool.js 486 B

123456789101112131415161718
  1. /**
  2. */
  3. var Mysql = require('mysql');
  4. var pool;
  5. var client = {
  6. getConnection:function(callback){
  7. if(!pool) throw new Error("Mysql pool not created!");
  8. if(!callback || typeof(callback)!='function') throw new Error("Mysql pool get connection lost callback!");
  9. pool.getConnection(function(err,connection){
  10. callback(err,connection);
  11. });
  12. }
  13. }
  14. exports.instance = function(config){
  15. pool = Mysql.createPool(config)
  16. return client;
  17. };