Skip to content

Commit a850c5c

Browse files
committed
Rename 'hooks.bla' to 'onBla'
1 parent 001771f commit a850c5c

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

packages/pg-pool/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ class Pool extends EventEmitter {
277277
} else {
278278
this.log('new client connected')
279279

280-
if (this.options.hooks && this.options.hooks.connect) {
280+
if (this.options.onConnect) {
281281
let hookResult
282282
try {
283-
hookResult = this.options.hooks.connect(client)
283+
hookResult = this.options.onConnect(client)
284284
} catch (hookErr) {
285285
this._clients = this._clients.filter((c) => c !== client)
286286
client.end(() => {

packages/pg-pool/test/lifecycle-hooks.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ const Pool = require('..')
77
describe('lifecycle hooks', () => {
88
it('are called on connect', async () => {
99
const pool = new Pool({
10-
hooks: {
11-
connect: (client) => {
12-
client.HOOK_CONNECT_COUNT = (client.HOOK_CONNECT_COUNT || 0) + 1
13-
},
10+
onConnect: (client) => {
11+
client.HOOK_CONNECT_COUNT = (client.HOOK_CONNECT_COUNT || 0) + 1
1412
},
1513
})
1614
const client = await pool.connect()
@@ -25,11 +23,9 @@ describe('lifecycle hooks', () => {
2523

2624
it('are called on connect with an async hook', async () => {
2725
const pool = new Pool({
28-
hooks: {
29-
connect: async (client) => {
30-
const res = await client.query('SELECT 1 AS num')
31-
client.HOOK_CONNECT_RESULT = res.rows[0].num
32-
},
26+
onConnect: async (client) => {
27+
const res = await client.query('SELECT 1 AS num')
28+
client.HOOK_CONNECT_RESULT = res.rows[0].num
3329
},
3430
})
3531
const client = await pool.connect()
@@ -46,10 +42,8 @@ describe('lifecycle hooks', () => {
4642

4743
it('errors out the connect call if the async connect hook rejects', async () => {
4844
const pool = new Pool({
49-
hooks: {
50-
connect: async (client) => {
51-
await client.query('SELECT INVALID HERE')
52-
},
45+
onConnect: async (client) => {
46+
await client.query('SELECT INVALID HERE')
5347
},
5448
})
5549
try {
@@ -63,10 +57,8 @@ describe('lifecycle hooks', () => {
6357

6458
it('errors out the connect call if the connect hook throws', async () => {
6559
const pool = new Pool({
66-
hooks: {
67-
connect: () => {
68-
throw new Error('connect hook error')
69-
},
60+
onConnect: () => {
61+
throw new Error('connect hook error')
7062
},
7163
})
7264
try {

0 commit comments

Comments
 (0)