Skip to content

Commit

Permalink
feat(pool): expose maxUses pool config option (sequelize#12101)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskchew authored and Lino Carnesecca committed May 5, 2020
1 parent 6ec9bd7 commit 4f7a4d3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/dialects/abstract/connection-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class ConnectionManager {
min: config.pool.min,
acquireTimeoutMillis: config.pool.acquire,
idleTimeoutMillis: config.pool.idle,
reapIntervalMillis: config.pool.evict
reapIntervalMillis: config.pool.evict,
maxUses: config.pool.maxUses
});

debug(`pool created with max/min: ${config.pool.max}/${config.pool.min}, no replication`);
Expand Down Expand Up @@ -211,7 +212,8 @@ class ConnectionManager {
min: config.pool.min,
acquireTimeoutMillis: config.pool.acquire,
idleTimeoutMillis: config.pool.idle,
reapIntervalMillis: config.pool.evict
reapIntervalMillis: config.pool.evict,
maxUses: config.pool.maxUses
}),
write: new Pool({
name: 'sequelize:write',
Expand All @@ -226,7 +228,8 @@ class ConnectionManager {
min: config.pool.min,
acquireTimeoutMillis: config.pool.acquire,
idleTimeoutMillis: config.pool.idle,
reapIntervalMillis: config.pool.evict
reapIntervalMillis: config.pool.evict,
maxUses: config.pool.maxUses
})
};

Expand Down
1 change: 1 addition & 0 deletions lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Sequelize {
* @param {number} [options.pool.acquire=60000] The maximum time, in milliseconds, that pool will try to get connection before throwing error
* @param {number} [options.pool.evict=1000] The time interval, in milliseconds, after which sequelize-pool will remove idle connections.
* @param {Function} [options.pool.validate] A function that validates a connection. Called with client. The default function checks that client is an object, and that its state is not disconnected
* @param {number} [options.pool.maxUses=Infinity] The number of times a connection can be used before discarding it for a replacement, [`used for eventual cluster rebalancing`](https://github.com/sequelize/sequelize-pool).
* @param {boolean} [options.quoteIdentifiers=true] Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them. WARNING: Setting this to false may expose vulnerabilities and is not recommended!
* @param {string} [options.transactionType='DEFERRED'] Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible options. Sqlite only.
* @param {string} [options.isolationLevel] Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options.
Expand Down
5 changes: 5 additions & 0 deletions types/lib/sequelize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export interface PoolOptions {
*/
evict?: number;

/**
* The number of times to use a connection before closing and replacing it. Default is Infinity
*/
maxUses?: number;

/**
* A function that validates a connection. Called with client. The default function checks that client is an
* object, and that its state is not disconnected
Expand Down

0 comments on commit 4f7a4d3

Please sign in to comment.