首页 > 解决方案 > Node.js Sequelize 获取原生池

问题描述

我使用Sequelizeandpg来查询Postgres

我找到了获得 Sequelize 连接的方法

sequilize.connectionManager.getConnection()
  .then((connection) => {})

有什么办法得到pool吗?

标签: node.jssequelize.jspg

解决方案


There is an option to use pool of connections from Sequelize this way

sequelize.connectionManager.getConnection()
  .then((connection) => {
    connection.query('SOME SQL;')
     .then(() => {
       sequilize.connectionManager.releaseConnection(connection);
     })
  })

It returns connection from the pool and then connection has to be released


推荐阅读