diff --git a/src/bridge.ts b/src/bridge.ts index 8ba9f93..c58a973 100644 --- a/src/bridge.ts +++ b/src/bridge.ts @@ -189,8 +189,12 @@ export const createPostgresBridge = (postgres: typeof Postgres) => { rows: Array.from(resultArray), }; }, - release: async () => { - await this.pool.release(compatibleConnection); + release: async (remove: boolean = false) => { + if (remove) { + await this.pool.destroy(compatibleConnection); + } else { + await this.pool.release(compatibleConnection); + } }, }; diff --git a/test/postgres-bridge/bridge.ts b/test/postgres-bridge/bridge.ts index 9440e33..9ce36f8 100644 --- a/test/postgres-bridge/bridge.ts +++ b/test/postgres-bridge/bridge.ts @@ -191,6 +191,20 @@ for (const { t.is(pool.idleCount, 1); }); + test(clientName + ': connection.release(true) removes connection from the pool', async (t) => { + const pool = new Pool({ + user: 'postgres', + }); + + const connection = await pool.connect(); + + t.is(pool.totalCount, 1); + + await connection.release(true); + + t.is(pool.totalCount, 0); + }); + test(clientName + ': connection.query() returns integers', async (t) => { const pool = new Pool({ user: 'postgres',