Search code examples
node.jssequelize.jspg

Node.js Sequelize get native pool


I use Sequelize and pg to make queries to Postgres

I've found the way how to get a Sequelize connection

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

Is there any way to get pool?


Solution

  • 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