import * as events from "./events"; export interface SQLConnectionPoolAbstraction { pool: TPool; getConnection: ( pool: TPool, eventEmitter: events.SQLEventEmitter | undefined, ) => Promise; } export type CloseConnection = () => Promise; export const useConnectionPoolAsync = async ( { pool, getConnection }: SQLConnectionPoolAbstraction, eventEmitter: events.SQLEventEmitter | undefined, use: (connection: TConnection) => Promise, ) => { let connection: | readonly [TConnection, CloseConnection] | undefined = undefined; try { connection = await getConnection(pool, eventEmitter); return await use(connection[0]); } finally { if (connection) { await connection[1](); } } };