Skip to content

Commit 4e44e96

Browse files
committed
feat: implement pool.end()
1 parent dcedc42 commit 4e44e96

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Known incompatibilities:
4949

5050
* `connection.processID` not implemented
5151
* `pool._pulseQueue` not implemented
52+
* callback (CPS) interface not implemented (use promises instead)
5253

5354
Please submit PR if you require additional compatibility.
5455

src/bridge.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const createBridge = (postgres: typeof Postgres) => {
108108

109109
const compatibleConnection = {
110110
end: async () => {
111-
await connection.end();
111+
await this.pool.destroy(compatibleConnection);
112112
},
113113
off: connectionEvents.off.bind(connectionEvents),
114114
on: connectionEvents.on.bind(connectionEvents),
@@ -190,9 +190,7 @@ export const createBridge = (postgres: typeof Postgres) => {
190190
}
191191

192192
public async end () {
193-
for (const client of this._clients) {
194-
await client.end();
195-
}
193+
await this.pool.clear();
196194
}
197195
};
198196
};

test/postgres-bridge/bridge.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ for (const {
117117
await connection2.end();
118118
});
119119

120+
test(clientName + ': pool.end() destroys all connections', async (t) => {
121+
const pool = new Pool({
122+
user: 'postgres',
123+
});
124+
125+
t.is(pool.totalCount, 0);
126+
127+
const connection1 = await pool.connect();
128+
const connection2 = await pool.connect();
129+
130+
t.is(pool.totalCount, 2);
131+
132+
await connection1.release();
133+
await connection2.release();
134+
135+
await pool.end();
136+
137+
t.is(pool.totalCount, 0);
138+
});
139+
120140
test(clientName + ': connection.release() releases connection back to the pool', async (t) => {
121141
const pool = new Pool({
122142
user: 'postgres',

0 commit comments

Comments
 (0)