[英]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 .
因此,如果我将max的值设置为 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.我对 Sequelize 一无所知,但我们可以通过这种方式创建连接。我认为这对您有一点帮助。
/**
* 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.对于
"sequelize": "^5.21.3"
,您不能pool.max
设置为0
。 If you do this, sequelize
will throw an error:如果你这样做,
sequelize
会抛出一个错误:
max must be an integer > 0
max 必须是一个大于 0 的整数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.