title: Closing idle connections: Does Sequelize allow me to view how long a DB connection has been idle?
body: <p>My app server uses a database per tenant and I need to connect to many databases at once. To do so with Sequelize I maintain a db pool where I add a connection to a Map:</p>
  <pre><code>addConnection(dbKey) {
    const sequelize = new Sequelize(
      dbKey,
      &quot;username&quot;,
      &quot;password&quot;,
      {
        host: localhost,
        port: 5000,
        schema: 'main',
        dialect: 'postgres'
      }
    );
  
    const models = {
      sequelize: sequelize,
      customerData: CustomerData(sequelize, DataTypes)
    }
    
    this.dbPool.set(dbKey, models);
  }
  </code></pre>
  <p>This allows me to retrieve sequelize instances as needed. Currently I do not see any support for single sequelize instances managing connections to multiple databases. And because I am maintaining my own Map of connections it seems that I would need to perform the task of releasing idle connections.</p>
  <p>I would like to close idle connections and drop them from the Map if they are not used for a certain interval. I have considered a few ways of doing so but do not know which are feasible. It really comes down to 2..</p>
  <p>1 - set options.pool.idle for the Sequelize instance.</p>
  <pre><code>&gt; The maximum time, in milliseconds, that a connection can be idle before being released.
  </code></pre>
  <p>AFAIK this does not do what I want, this only sets a timeout when there is a connection pool for the same DB so this clearly won't work.</p>
  <p>2 - Use SetInterval to close connections and drop their reference from the Map object when idle.</p>
  <pre><code>a) When opening connection, set a timestamp along with connection.
  
  b) Whenever the sequelize instance is used to make a query, update the timestamp.
  
  c) Every minute or so, close and free any connections that have been idle for longer than some time period.
  </code></pre>
  <p>To do so it would be great if there were some internal field in Sequelize or getter that would let me see when the connection was last used. Looking at the API for the Sequelize and model instances, I do not see such a field or method. Is there a way to determine the time a connection was last used in the Sequelize library?</p>