简体   繁体   中英

Connection Pooling in Nodejs (Using sequelize)

I write the code below. According to my understanding the "max:" in pool shows the max number of connection we can create in pool. So if I set the value of max as 0 . Then it should not established any connection. I just want to clarify this.

 var sequelize = new Sequelize( process.env.DATABASE_NAME, process.env.DATABASE_USERNAME, process.env.DATABASE_PASSWORD, { pool:{ max: 0, min: 0, idle: 10000, acquire:30000 }, logging: console.log("connection created"), host: process.env.DATABASE_HOST, dialect: 'mysql', operatorsAliases: false } );

I have no idea about Sequelize but simply we can create a connection this way.I think this will be little bit helpful for you.

   /**
 * create connection pool
 */
var con = mysql.createPool({
    connectionLimit: 100000,
    host: 'enter host',
    user: process.env.DATABASE_USERNAME,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME
});

con.getConnection(async function(err, connection) {
    let result=connection.query('SELECT * FROM table_name');
    console.log(result);
    if(err) throw err;

})

what's wrong with the way they have it set up in their examples exactly?

const sequelize = new Sequelize(config.db.uri, {
  pool: {
    max: 100,
    min: 0,
    idle: 10000,
  },
  dialectOptions: {
    ssl: config.db.ssl,
  },
  // logging: logger.debug.bind(logger),
});

the models utilize it on their own... what am i missing here?

For "sequelize": "^5.21.3" , you can't set pool.max to 0 anymore. If you do this, sequelize will throw an error:

max must be an integer > 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM