在 Sequelize 操作后关闭我的连接是一种好习惯吗?

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

目前我正在使用 NodeJS/TypeScript 在 Sequelize 之上设计一个应用程序,我想知道它是否会导致不关闭连接的性能问题。

例如,在微服务中,我需要来自 1 个实体的数据。

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

调用findOne后是否需要关闭连接?

我的理解是以下配置定义了多个并发连接,idle 是一个参数,使连接管理器关闭空闲连接:

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
    }
  }
}

欢迎任何建议

Sequelize 维护一个内部 database connection pool,这就是 pool 参数的用途,所以这不是必需的。每个调用实际上临时借用一个连接,然后 returns 完成后将其放入池中。

手动关闭该连接可能会污染池并导致性能问题。

如果你不关闭Sequelize连接,微服务仍然会运行直到连接超时(空闲时间池参数)。我建议关闭Sequelize连接,至少在微服务..