Advertisement
Guest User

connectionPool

a guest
Oct 5th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const config1 = {
  2.     user: 'web',
  3.     password: '19461946',
  4.     server: '192.168.44.110', // You can use 'localhost\\instance' to connect to named instance
  5.     database: 'Testing20172018',
  6.     port: '1433',
  7.     options: {
  8.         trustedConnection: true
  9.       }
  10. }
  11.  
  12. const config = {
  13.     user: 'usuario_node',
  14.     password: 'node123',
  15.     server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
  16.     database: 'pruebas_node',
  17.     port: '1433',
  18.     options: {
  19.         trustedConnection: true
  20.       }
  21. }
  22. config.parseJSON =true
  23. var sql = require('mssql')
  24. const secret= 'Ccross2in0ven0ta1ri7o'
  25. const saltRounds = 10;
  26.  
  27. function getConnectionPoolGlobal(config){
  28.     function conect(resolve,reject){
  29.         if (global.poolGlobal){
  30.             console.log('Reutilizando pool '+poolGlobal.listenerCount())
  31.             resolve(poolGlobal)
  32.         }
  33.         else{
  34.         new sql.ConnectionPool(config).connect().then(poolObt=>{
  35.             global.poolGlobal=poolObt
  36.             resolve(global.poolGlobal)
  37.             console.log('Nuevo pool Creado')
  38.         }).catch(err =>{
  39.             reject(err)
  40.         })
  41.         }      
  42.     }
  43.     return new Promise(conect)
  44. }
  45.  
  46. function getConnectionPool(config,sql){
  47.     function getpool(resolve,reject){
  48.         new sql.ConnectionPool(config).connect().then(pool=>{
  49.             resolve(pool)
  50.         }).catch(err =>{
  51.             reject(err)
  52.         })
  53.     }
  54.     return new Promise(getpool)
  55. }
  56. module.exports={
  57.     "config":config,
  58.     "getConnectionPool":getConnectionPool,
  59.     "getConnectionPoolGlobal":getConnectionPoolGlobal,
  60.     "saltRounds":saltRounds,
  61.     "secret":secret
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement