-
Notifications
You must be signed in to change notification settings - Fork 25
/
pg-pool.pub.ts
28 lines (22 loc) · 920 Bytes
/
pg-pool.pub.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import {channel, IModulePatcher, PatchFunction} from "diagnostic-channel";
import {EventEmitter} from "events";
import * as pg from "pg";
function postgresPool1PatchFunction(originalPgPool) {
const originalConnect = originalPgPool.prototype.connect;
originalPgPool.prototype.connect = function connect(callback?: Function): void | Promise<pg.PoolClient> {
if (callback) {
arguments[0] = channel.bindToContext(callback);
}
return originalConnect.apply(this, arguments);
};
return originalPgPool;
}
export const postgresPool1: IModulePatcher = {
versionSpecifier: ">= 1.0.0 < 3.0.0",
patch: postgresPool1PatchFunction,
};
export function enable() {
channel.registerMonkeyPatch("pg-pool", postgresPool1);
}