Skip to content

Commit 593c4d6

Browse files
committed
feat: support connection.release(true)
1 parent 38b69de commit 593c4d6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/bridge.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ export const createPostgresBridge = (postgres: typeof Postgres) => {
189189
rows: Array.from(resultArray),
190190
};
191191
},
192-
release: async () => {
193-
await this.pool.release(compatibleConnection);
192+
release: async (remove: boolean = false) => {
193+
if (remove) {
194+
await this.pool.destroy(compatibleConnection);
195+
} else {
196+
await this.pool.release(compatibleConnection);
197+
}
194198
},
195199
};
196200

test/postgres-bridge/bridge.ts

+14
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ for (const {
191191
t.is(pool.idleCount, 1);
192192
});
193193

194+
test(clientName + ': connection.release(true) removes connection from the pool', async (t) => {
195+
const pool = new Pool({
196+
user: 'postgres',
197+
});
198+
199+
const connection = await pool.connect();
200+
201+
t.is(pool.totalCount, 1);
202+
203+
await connection.release(true);
204+
205+
t.is(pool.totalCount, 0);
206+
});
207+
194208
test(clientName + ': connection.query() returns integers', async (t) => {
195209
const pool = new Pool({
196210
user: 'postgres',

0 commit comments

Comments
 (0)