Skip to content

Commit 3cc9f34

Browse files
committed
feat: add "remove" event
1 parent 1e0d051 commit 3cc9f34

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Supported features:
4242
* `pool.connect`
4343
* `connection.query`
4444
* `connect` event
45+
* `remove` event
4546
* `notice` event
4647

4748
Known incompatibilities:

src/bridge.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export const createBridge = (postgres: typeof Postgres) => {
157157

158158
public async _remove (client: {end: () => Promise<void>, }) {
159159
await client.end();
160+
161+
this.poolEvents.emit('remove', client);
160162
}
161163

162164
public get _clients (): BridgetClient[] {

test/postgres-bridge/bridge.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ for (const {
4242
t.is(spy.firstCall.args[0], connection);
4343
});
4444

45+
test(clientName + ': "remove" event is fired when connection is removed', async (t) => {
46+
const pool = new Pool({
47+
user: 'postgres',
48+
});
49+
50+
const spy = sinon.spy();
51+
52+
pool.on('remove', spy);
53+
54+
const connection = await pool.connect();
55+
56+
await pool._remove(connection);
57+
58+
t.true(spy.called);
59+
60+
t.is(spy.firstCall.args[0], connection);
61+
});
62+
4563
test(clientName + ': "notice event is fired when connection produces a notice"', async (t) => {
4664
const pool = new Pool({
4765
user: 'postgres',

0 commit comments

Comments
 (0)