postgrelize / ConnectionManagerContract
Interface: ConnectionManagerContract ​
Defined in: src/connection/connection-types.ts:105
Acquire / release contract of sequelize.connectionManager. Every query, transaction, COPY and sync of the instance takes its pooled connection through getConnection and gives it back through releaseConnection, looked up on the manager at call time: both may be replaced on the instance (wrapped) to route connections.
Example ​
const manager = sequelize.connectionManager;
const defaultGet = manager.getConnection.bind(manager);
manager.getConnection = async (options) => {
console.log('acquiring', options?.type ?? 'write');
return defaultGet(options);
};Properties ​
pool ​
readonlypool:ConnectionPool
Defined in: src/connection/connection-types.ts:162
Live connection counts of the instance's pools, for health gauges.
Example ​
const { size, using, waiting, maxSize } = sequelize.connectionManager.pool;Methods ​
destroyConnection() ​
destroyConnection(
connection):Promise<void>
Defined in: src/connection/connection-types.ts:153
Removes a broken connection from the pool that owns it instead of returning it: the client is closed and the pool opens a replacement when one is needed. The connection must not be used or released afterwards (a later release is ignored).
Parameters ​
connection ​
Connection obtained from getConnection.
Returns ​
Promise<void>
Resolves when the connection is removed from its pool.
Example ​
const connection = await sequelize.connectionManager.getConnection({ type: 'read' });
try {
await connection.query('SELECT 1');
await sequelize.connectionManager.releaseConnection(connection);
} catch (error) {
await sequelize.connectionManager.destroyConnection(connection);
throw error;
}getConnection() ​
getConnection(
options?):Promise<Client>
Defined in: src/connection/connection-types.ts:118
Acquires a pooled connection.
Parameters ​
options? ​
Readonly<{ type?: "read" | "write" | "SELECT"; useMaster?: boolean; uuid?: string; }>
Replica selection and transaction id.
Returns ​
Promise<Client>
A connection that stays checked out until it is passed to releaseConnection.
Example ​
const connection = await sequelize.connectionManager.getConnection({ type: 'read' });
await sequelize.connectionManager.releaseConnection(connection);releaseConnection() ​
releaseConnection(
connection):void|Promise<void>
Defined in: src/connection/connection-types.ts:132
Returns a connection obtained from getConnection to the pool that owns it.
Parameters ​
connection ​
Connection to release.
Returns ​
void | Promise<void>
Nothing (may be asynchronous).
Example ​
const connection = await sequelize.connectionManager.getConnection();
await connection.query('SELECT 1');
await sequelize.connectionManager.releaseConnection(connection);