Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to close my connection after Sequelize operations?

currently I'm designing an app on top of Sequelize using NodeJS/TypeScript, and I'm wondering if it can cause performance issues not closing a connection.

For instance, in a micro service, I need data from 1 entity.

const resolver = async (,,{db}) => {
  const entity1 = await db.models.Entity1.findOne()
  return entity1
}

Is it required to close the connection after having called findOne?

My understanding is that the following config defines a number of concurrent connections and idle is a parameter making the connection manager closing the connection of idle ones:

module.exports = {
  development: {
    host: 'db.sqlite',
    dialect: 'sqlite',
    pool: {
        max:5,
        min:0,
        idle:10000
    }
  },
  test: {
    host: 'test.sqlite',
    dialect: 'sqlite',
    pool: {
        max:5,
        min:0,
        idle:10000
    }
  }
}

Any advice is welcome

like image 905
dbrrt Avatar asked Sep 15 '25 05:09

dbrrt


1 Answers

Sequelize maintains an internal database connection pool, that's what the pool parameters are for, so this isn't necessary. Each call actually borrows a connection temporarily and then returns it to the pool when done.

Closing that connection manually may poison the pool and cause performance issues.

like image 177
tadman Avatar answered Sep 17 '25 19:09

tadman