Skip to content

Commit

Permalink
feat: support connection.release(true)
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Aug 3, 2022
1 parent 38b69de commit 593c4d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
};

Expand Down
14 changes: 14 additions & 0 deletions test/postgres-bridge/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 593c4d6

Please sign in to comment.