UNPKG

2.54 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.enable = exports.tedious = void 0;
15// Copyright (c) Microsoft Corporation. All rights reserved.
16// Licensed under the MIT license. See LICENSE file in the project root for details.
17var diagnostic_channel_1 = require("diagnostic-channel");
18var tediousPatchFunction = function (originalTedious) {
19 var originalMakeRequest = originalTedious.Connection.prototype.makeRequest;
20 originalTedious.Connection.prototype.makeRequest = function makeRequest() {
21 function getPatchedCallback(origCallback) {
22 var start = process.hrtime();
23 var data = {
24 query: {},
25 database: {
26 host: null,
27 port: null
28 },
29 result: null,
30 error: null,
31 duration: 0
32 };
33 return diagnostic_channel_1.channel.bindToContext(function (err, rowCount, rows) {
34 var end = process.hrtime(start);
35 data = __assign(__assign({}, data), { database: {
36 host: this.connection.config.server,
37 port: this.connection.config.options.port
38 }, result: !err && { rowCount: rowCount, rows: rows }, query: {
39 text: this.parametersByName.statement.value
40 }, error: err, duration: Math.ceil((end[0] * 1e3) + (end[1] / 1e6)) });
41 diagnostic_channel_1.channel.publish("tedious", data);
42 origCallback.call(this, err, rowCount, rows);
43 });
44 }
45 var request = arguments[0];
46 arguments[0].callback = getPatchedCallback(request.callback);
47 originalMakeRequest.apply(this, arguments);
48 };
49 return originalTedious;
50};
51exports.tedious = {
52 versionSpecifier: ">= 6.0.0 < 9.0.0",
53 patch: tediousPatchFunction
54};
55function enable() {
56 diagnostic_channel_1.channel.registerMonkeyPatch("tedious", exports.tedious);
57}
58exports.enable = enable;
59//# sourceMappingURL=tedious.pub.js.map
\No newline at end of file