Skip to content

Commit a04f710

Browse files
authored
🤖 Merge PR DefinitelyTyped#74779 Add onConnect callback type for PoolConfig by @ericbsantana
1 parent cbb2914 commit a04f710

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

‎types/pg/index.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface PoolConfig extends ClientConfig {
5454
maxUses?: number | undefined;
5555
maxLifetimeSeconds?: number | undefined;
5656
Client?: (new() => ClientBase) | undefined;
57+
onConnect?: ((client: ClientBase) => void) | undefined;
5758
}
5859

5960
export interface QueryConfig<I = any[]> {

‎types/pg/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/pg",
4-
"version": "8.18.9999",
4+
"version": "8.20.9999",
55
"projects": [
66
"https://github.com/brianc/node-postgres"
77
],

‎types/pg/pg-tests.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,16 @@ const bindConfig = {
432432

433433
const con = new Connection();
434434
con.bind(bindConfig, true);
435+
436+
const poolWithOnConnect = new Pool({
437+
onConnect: (client) => {
438+
client.query("SELECT 1").then(result => {
439+
console.log(result.rows[0].number);
440+
});
441+
console.log("onConnect callback is working!");
442+
},
443+
});
444+
445+
poolWithOnConnect.connect().then(client => {
446+
console.log("client connected");
447+
});

0 commit comments

Comments
 (0)