Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. var mySql = require("mysql");
  2. var Promise = require("promise");
  3.  
  4. var pool = mySql.createPool({
  5. host : "localhost",
  6. user : "root",
  7. password : "rahul",
  8. database : "testDb", //schema
  9. connectionLimit : 13, // at a time 13 connection be created in pool
  10. });
  11.  
  12. function getDepartments(){
  13. return new Promise(fn);
  14.  
  15. function fn(resolve,reject){
  16. pool.getConnection(function(err,con){
  17. if(err){
  18. return reject(err);
  19. }else{
  20. con.query("select * from departmentTbl",function(err,rows){
  21. if(err){
  22. return reject(err);
  23. }else{
  24. con.release(); // releasing connection to pool
  25. return resolve(rows);
  26. }
  27. });
  28. }
  29. }); // getConnection
  30. }// fn
  31. } // getDepartments
  32.  
  33. getDepartments().then(function(rows){
  34. console.log(rows);
  35. }).catch(function(err){
  36. console.log(err);
  37. }).done(function(){
  38. pool.end(); // closing all connections in pool
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement