postgrejs 2.12.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +215 -191
  2. package/README.md +25 -25
  3. package/cjs/connection/connection.js +10 -5
  4. package/cjs/connection/cursor.js +2 -4
  5. package/cjs/connection/intl-connection.js +19 -12
  6. package/cjs/connection/pool.js +12 -6
  7. package/cjs/connection/prepared-statement.js +6 -3
  8. package/cjs/data-types/bytea-type.js +2 -4
  9. package/cjs/data-types/numeric-type.js +2 -2
  10. package/cjs/data-types/time-type.js +2 -1
  11. package/cjs/data-types/timestamp-type.js +2 -1
  12. package/cjs/data-types/timestamptz-type.js +2 -1
  13. package/cjs/index.js +26 -39
  14. package/cjs/protocol/frontend.js +8 -5
  15. package/cjs/protocol/pg-socket.js +33 -31
  16. package/cjs/protocol/sasl.js +14 -14
  17. package/cjs/protocol/smart-buffer.js +2 -24
  18. package/cjs/util/array-calculatedim.js +1 -2
  19. package/cjs/util/bigint-methods.js +2 -3
  20. package/cjs/util/config-from-env.js +1 -2
  21. package/cjs/util/connection-config.js +8 -11
  22. package/cjs/util/convert-row-to-object.js +1 -2
  23. package/cjs/util/decode-binaryarray.js +1 -2
  24. package/cjs/util/encode-binaryarray.js +1 -2
  25. package/cjs/util/escape-literal.js +1 -2
  26. package/cjs/util/fast-parseint.js +1 -2
  27. package/cjs/util/get-parsers.js +1 -2
  28. package/cjs/util/parse-array.js +1 -2
  29. package/cjs/util/parse-datetime.js +1 -2
  30. package/cjs/util/parse-row.js +1 -2
  31. package/cjs/util/parse-time.js +2 -2
  32. package/cjs/util/stringify-arrayliteral.js +1 -2
  33. package/cjs/util/stringify-for-sql.js +2 -3
  34. package/cjs/util/wrap-row-description.js +1 -2
  35. package/esm/connection/connection.js +10 -5
  36. package/esm/connection/intl-connection.js +17 -10
  37. package/esm/connection/pool.js +12 -6
  38. package/esm/connection/prepared-statement.js +6 -3
  39. package/esm/data-types/time-type.js +2 -1
  40. package/esm/data-types/timestamp-type.js +2 -1
  41. package/esm/data-types/timestamptz-type.js +2 -1
  42. package/esm/index.js +5 -5
  43. package/esm/protocol/frontend.js +8 -5
  44. package/esm/protocol/pg-socket.js +28 -24
  45. package/esm/protocol/sasl.js +12 -10
  46. package/esm/util/connection-config.js +4 -4
  47. package/package.json +5 -5
  48. package/typings/connection/connection.d.ts +0 -1
  49. package/typings/connection/cursor.d.ts +0 -1
  50. package/typings/connection/prepared-statement.d.ts +0 -1
  51. package/typings/index.d.ts +5 -5
  52. package/typings/interfaces/database-connection-params.d.ts +1 -1
  53. package/typings/protocol/backend.d.ts +0 -1
  54. package/typings/protocol/buffer-reader.d.ts +0 -1
  55. package/typings/protocol/frontend.d.ts +0 -1
  56. package/typings/protocol/pg-socket.d.ts +0 -1
  57. package/typings/protocol/protocol.d.ts +0 -1
  58. package/typings/protocol/smart-buffer.d.ts +0 -1
  59. package/typings/safe-event-emitter.d.ts +0 -1
  60. package/typings/types.d.ts +0 -1
  61. package/typings/util/bigint-methods.d.ts +0 -1
  62. package/typings/util/decode-binaryarray.d.ts +0 -1
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SASL = void 0;
4
+ const tslib_1 = require("tslib");
7
5
  /* eslint-disable no-bitwise */
8
- const crypto_1 = __importDefault(require("crypto"));
6
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
9
7
  var SASL;
10
8
  (function (SASL) {
11
9
  const CLIENT_KEY = 'Client Key';
@@ -39,6 +37,8 @@ var SASL;
39
37
  case 'i':
40
38
  iteration = parseInt(i.substring(2), 10);
41
39
  break;
40
+ default:
41
+ break;
42
42
  }
43
43
  }
44
44
  if (!nonce)
@@ -75,25 +75,25 @@ var SASL;
75
75
  throw new Error('SASL: Server signature does not match');
76
76
  }
77
77
  SASL.finalizeSession = finalizeSession;
78
- function firstMessageBare(username, nonce) {
78
+ const firstMessageBare = function (username, nonce) {
79
79
  return `n=${username},r=${nonce}`;
80
- }
80
+ };
81
81
  /**
82
82
  * Hi() is, essentially, PBKDF2 [RFC2898] with HMAC() as the
83
83
  * pseudorandom function (PRF) and with dkLen == output length of
84
84
  * HMAC() == output length of H()
85
85
  */
86
- function hi(text, salt, iterations) {
86
+ const hi = function (text, salt, iterations) {
87
87
  return crypto_1.default.pbkdf2Sync(text, Buffer.from(salt, 'base64'), iterations, 32, 'sha256');
88
- }
88
+ };
89
89
  const encode64 = str => Buffer.from(str).toString('base64');
90
- function hmac(key, msg) {
90
+ const hmac = function (key, msg) {
91
91
  return crypto_1.default.createHmac('sha256', key).update(msg).digest();
92
- }
93
- function hash(data) {
92
+ };
93
+ const hash = function (data) {
94
94
  return crypto_1.default.createHash('sha256').update(data).digest();
95
- }
96
- function xor(a, b) {
95
+ };
96
+ const xor = function (a, b) {
97
97
  a = Buffer.isBuffer(a) ? a : Buffer.from(a);
98
98
  b = Buffer.isBuffer(b) ? b : Buffer.from(b);
99
99
  if (a.length !== b.length)
@@ -104,5 +104,5 @@ var SASL;
104
104
  out[i] = a[i] ^ b[i];
105
105
  }
106
106
  return out;
107
- }
107
+ };
108
108
  })(SASL || (exports.SASL = SASL = {}));
@@ -1,30 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.SmartBuffer = void 0;
27
- const os = __importStar(require("os"));
4
+ const tslib_1 = require("tslib");
5
+ const os = tslib_1.__importStar(require("os"));
28
6
  const bigint_methods_js_1 = require("../util/bigint-methods.js");
29
7
  const buffer_reader_js_1 = require("./buffer-reader.js");
30
8
  class SmartBuffer extends buffer_reader_js_1.BufferReader {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arrayCalculateDim = void 0;
3
+ exports.arrayCalculateDim = arrayCalculateDim;
4
4
  function arrayCalculateDim(arr) {
5
5
  if (!arr || arr.length === 0)
6
6
  return [0];
@@ -16,4 +16,3 @@ function arrayCalculateDim(arr) {
16
16
  iterate(arr, 1);
17
17
  return dim;
18
18
  }
19
- exports.arrayCalculateDim = arrayCalculateDim;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeBigUInt64BE = exports.readBigInt64BE = void 0;
3
+ exports.readBigInt64BE = readBigInt64BE;
4
+ exports.writeBigUInt64BE = writeBigUInt64BE;
4
5
  /* eslint-disable no-bitwise */
5
6
  const big0 = BigInt(0);
6
7
  const beAnd = BigInt('0xffffffff');
@@ -17,7 +18,6 @@ function readBigInt64BE(buf, offset = 0) {
17
18
  buf[++offset];
18
19
  return ((BigInt(val) << big32) + BigInt(buf[++offset] * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + last));
19
20
  }
20
- exports.readBigInt64BE = readBigInt64BE;
21
21
  function writeBigUInt64BE(buf, value, offset = 0) {
22
22
  // @ts-ignore
23
23
  let lo = Number(value & beAnd);
@@ -39,4 +39,3 @@ function writeBigUInt64BE(buf, value, offset = 0) {
39
39
  buf[offset] = hi;
40
40
  return offset + 8;
41
41
  }
42
- exports.writeBigUInt64BE = writeBigUInt64BE;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configFromEnv = void 0;
3
+ exports.configFromEnv = configFromEnv;
4
4
  const putil_varhelpers_1 = require("putil-varhelpers");
5
5
  function configFromEnv() {
6
6
  const env = process.env;
@@ -27,4 +27,3 @@ function configFromEnv() {
27
27
  }
28
28
  return result;
29
29
  }
30
- exports.configFromEnv = configFromEnv;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseConnectionString = exports.getConnectionConfig = void 0;
7
- const putil_merge_1 = __importDefault(require("putil-merge"));
3
+ exports.getConnectionConfig = getConnectionConfig;
4
+ exports.parseConnectionString = parseConnectionString;
5
+ const tslib_1 = require("tslib");
6
+ const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
8
7
  const config_from_env_js_1 = require("./config-from-env.js");
9
8
  function getConnectionConfig(config) {
10
9
  const cfg = (0, config_from_env_js_1.configFromEnv)();
@@ -23,16 +22,13 @@ function getConnectionConfig(config) {
23
22
  cfg.host = cfg.host || '127.0.0.1';
24
23
  return cfg;
25
24
  }
26
- exports.getConnectionConfig = getConnectionConfig;
27
25
  function parseConnectionString(str) {
28
26
  if (str.startsWith('/'))
29
27
  str = 'socket:/' + str;
30
28
  if (!str.includes('://'))
31
29
  str = 'postgres://' + str;
32
30
  const parsed = new URL(str);
33
- const getFirst = (v) => {
34
- return typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '';
35
- };
31
+ const getFirst = (v) => (typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '');
36
32
  const cfg = {};
37
33
  cfg.host = decodeURI(parsed.hostname || '');
38
34
  if (parsed.port)
@@ -54,12 +50,13 @@ function parseConnectionString(str) {
54
50
  cfg.database = decodeURI(getFirst(parsed.searchParams.get('db')));
55
51
  if (parsed.searchParams.get('schema'))
56
52
  cfg.schema = decodeURI(getFirst(parsed.searchParams.get('schema')));
57
- if (parsed.searchParams.get('application_name'))
53
+ if (parsed.searchParams.get('application_name')) {
58
54
  cfg.applicationName = decodeURI(getFirst(parsed.searchParams.get('application_name')));
55
+ }
59
56
  if (parsed.username)
60
57
  cfg.user = parsed.username;
61
58
  if (parsed.password)
62
59
  cfg.password = parsed.password;
60
+ cfg.requireSSL = parsed.searchParams.get('sslmode') === 'require';
63
61
  return cfg;
64
62
  }
65
- exports.parseConnectionString = parseConnectionString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertRowToObject = void 0;
3
+ exports.convertRowToObject = convertRowToObject;
4
4
  function convertRowToObject(fields, row) {
5
5
  const out = {};
6
6
  const l = row.length;
@@ -10,4 +10,3 @@ function convertRowToObject(fields, row) {
10
10
  }
11
11
  return out;
12
12
  }
13
- exports.convertRowToObject = convertRowToObject;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeBinaryArray = void 0;
3
+ exports.decodeBinaryArray = decodeBinaryArray;
4
4
  const buffer_reader_js_1 = require("../protocol/buffer-reader.js");
5
5
  function decodeBinaryArray(buf, decoder, options = {}) {
6
6
  if (!buf.length)
@@ -36,4 +36,3 @@ function decodeBinaryArray(buf, decoder, options = {}) {
36
36
  }
37
37
  return readDim(0);
38
38
  }
39
- exports.decodeBinaryArray = decodeBinaryArray;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeBinaryArray = void 0;
3
+ exports.encodeBinaryArray = encodeBinaryArray;
4
4
  const constants_js_1 = require("../constants.js");
5
5
  const array_calculatedim_js_1 = require("./array-calculatedim.js");
6
6
  function encodeBinaryArray(io, value, itemOid, options, encode, encodeCalculateDimFn) {
@@ -42,4 +42,3 @@ function encodeBinaryArray(io, value, itemOid, options, encode, encodeCalculateD
42
42
  if (hasNull)
43
43
  io.buffer.writeInt32BE(1, zeroOffset + 4);
44
44
  }
45
- exports.encodeBinaryArray = encodeBinaryArray;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escapeLiteral = void 0;
3
+ exports.escapeLiteral = escapeLiteral;
4
4
  // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
5
5
  function escapeLiteral(str) {
6
6
  let backSlash = false;
@@ -24,4 +24,3 @@ function escapeLiteral(str) {
24
24
  out = ' E' + out;
25
25
  return out;
26
26
  }
27
- exports.escapeLiteral = escapeLiteral;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fastParseInt = void 0;
3
+ exports.fastParseInt = fastParseInt;
4
4
  function fastParseInt(str) {
5
5
  /* istanbul ignore next */
6
6
  if (typeof str === 'number')
@@ -29,4 +29,3 @@ function fastParseInt(str) {
29
29
  } while (++i < strLength);
30
30
  return neg ? -res : res;
31
31
  }
32
- exports.fastParseInt = fastParseInt;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getParsers = void 0;
3
+ exports.getParsers = getParsers;
4
4
  const constants_js_1 = require("../constants.js");
5
5
  const decode_binaryarray_js_1 = require("./decode-binaryarray.js");
6
6
  const parse_array_js_1 = require("./parse-array.js");
@@ -39,4 +39,3 @@ function getParsers(typeMap, fields) {
39
39
  }
40
40
  return parsers;
41
41
  }
42
- exports.getParsers = getParsers;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePostgresArray = void 0;
3
+ exports.parsePostgresArray = parsePostgresArray;
4
4
  function parsePostgresArray(s, opts) {
5
5
  if (!s)
6
6
  return;
@@ -58,4 +58,3 @@ function parsePostgresArray(s, opts) {
58
58
  iterate(out);
59
59
  return out.length ? out[0] : undefined;
60
60
  }
61
- exports.parsePostgresArray = parsePostgresArray;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDateTime = void 0;
3
+ exports.parseDateTime = parseDateTime;
4
4
  // noinspection RegExpUnnecessaryNonCapturingGroup
5
5
  const fast_parseint_js_1 = require("./fast-parseint.js");
6
6
  // noinspection RegExpUnnecessaryNonCapturingGroup
@@ -35,4 +35,3 @@ function parseDateTime(str, parseTime, parseTimeZone, utc) {
35
35
  return new Date(Date.UTC(...args));
36
36
  return new Date(...args);
37
37
  }
38
- exports.parseDateTime = parseDateTime;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRow = void 0;
3
+ exports.parseRow = parseRow;
4
4
  function parseRow(parsers, row, options) {
5
5
  const l = row.length;
6
6
  let i;
@@ -8,4 +8,3 @@ function parseRow(parsers, row, options) {
8
8
  row[i] = row[i] == null ? null : parsers[i].call(undefined, row[i], options);
9
9
  }
10
10
  }
11
- exports.parseRow = parseRow;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTime = exports.TIME_PATTERN = exports.STRICT_TIME_PATTERN = void 0;
3
+ exports.TIME_PATTERN = exports.STRICT_TIME_PATTERN = void 0;
4
+ exports.parseTime = parseTime;
4
5
  const fast_parseint_js_1 = require("./fast-parseint.js");
5
6
  // eslint-disable-next-line
6
7
  // noinspection RegExpUnnecessaryNonCapturingGroup
@@ -26,4 +27,3 @@ function parseTime(str, parseTimeZone, utc) {
26
27
  return new Date(Date.UTC(...args));
27
28
  return new Date(...args);
28
29
  }
29
- exports.parseTime = parseTime;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringifyArrayLiteral = void 0;
3
+ exports.stringifyArrayLiteral = stringifyArrayLiteral;
4
4
  const array_calculatedim_js_1 = require("./array-calculatedim.js");
5
5
  function stringifyArrayLiteral(value, options, encode) {
6
6
  const dim = (0, array_calculatedim_js_1.arrayCalculateDim)(value);
@@ -32,7 +32,6 @@ function stringifyArrayLiteral(value, options, encode) {
32
32
  };
33
33
  return writeDim(value, 0);
34
34
  }
35
- exports.stringifyArrayLiteral = stringifyArrayLiteral;
36
35
  function escapeArrayItem(str) {
37
36
  return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
38
37
  }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringifyValueForSQL = exports.stringifyArrayForSQL = void 0;
3
+ exports.stringifyArrayForSQL = stringifyArrayForSQL;
4
+ exports.stringifyValueForSQL = stringifyValueForSQL;
4
5
  const uuid_type_js_1 = require("../data-types/uuid-type.js");
5
6
  const escape_literal_js_1 = require("./escape-literal.js");
6
7
  function stringifyArrayForSQL(v, options, encode) {
7
8
  const arr = v.map(x => stringifyValueForSQL(x, options, encode));
8
9
  return 'ARRAY[' + arr.join(',') + ']';
9
10
  }
10
- exports.stringifyArrayForSQL = stringifyArrayForSQL;
11
11
  function stringifyValueForSQL(v, options, encode) {
12
12
  if (v == null)
13
13
  return 'null';
@@ -27,4 +27,3 @@ function stringifyValueForSQL(v, options, encode) {
27
27
  return (0, escape_literal_js_1.escapeLiteral)(JSON.stringify(v)) + '::json';
28
28
  return (0, escape_literal_js_1.escapeLiteral)('' + v);
29
29
  }
30
- exports.stringifyValueForSQL = stringifyValueForSQL;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapRowDescription = void 0;
3
+ exports.wrapRowDescription = wrapRowDescription;
4
4
  const constants_js_1 = require("../constants.js");
5
5
  function wrapRowDescription(typeMap, fields, columnFormat) {
6
6
  return fields.map((f, idx) => {
@@ -32,4 +32,3 @@ function wrapRowDescription(typeMap, fields, columnFormat) {
32
32
  return x;
33
33
  });
34
34
  }
35
- exports.wrapRowDescription = wrapRowDescription;
@@ -83,34 +83,37 @@ export class Connection extends SafeEventEmitter {
83
83
  if (this.state === ConnectionState.CLOSED || this._closing)
84
84
  return;
85
85
  /* istanbul ignore next */
86
- if (this.listenerCount('debug'))
86
+ if (this.listenerCount('debug')) {
87
87
  this.emit('debug', {
88
88
  location: 'Connection.close',
89
89
  connection: this,
90
90
  message: `[${this.processID}] closing`,
91
91
  });
92
+ }
92
93
  this._closing = true;
93
94
  if (this._intlCon.refCount > 0 && typeof terminateWait === 'number' && terminateWait > 0) {
94
95
  const startTime = Date.now();
95
96
  return this._captureErrorStack(new Promise((resolve, reject) => {
96
97
  /* istanbul ignore next */
97
- if (this.listenerCount('debug'))
98
+ if (this.listenerCount('debug')) {
98
99
  this.emit('debug', {
99
100
  location: 'Connection.close',
100
101
  connection: this,
101
102
  message: `[${this.processID}] waiting active queries`,
102
103
  });
104
+ }
103
105
  const timer = setInterval(() => {
104
106
  if (this._intlCon.refCount <= 0 || Date.now() > startTime + terminateWait) {
105
107
  clearInterval(timer);
106
108
  if (this._intlCon.refCount > 0) {
107
109
  /* istanbul ignore next */
108
- if (this.listenerCount('debug'))
110
+ if (this.listenerCount('debug')) {
109
111
  this.emit('debug', {
110
112
  location: 'Connection.close',
111
113
  connection: this,
112
114
  message: `[${this.processID}] terminate`,
113
115
  });
116
+ }
114
117
  this.emit('terminate');
115
118
  }
116
119
  this._close().then(resolve).catch(reject);
@@ -134,13 +137,14 @@ export class Connection extends SafeEventEmitter {
134
137
  async query(sql, options) {
135
138
  this._intlCon.assertConnected();
136
139
  /* istanbul ignore next */
137
- if (this.listenerCount('debug'))
140
+ if (this.listenerCount('debug')) {
138
141
  this.emit('debug', {
139
142
  location: 'Connection.query',
140
143
  connection: this,
141
144
  message: `[${this.processID}] query | ${sql}`,
142
145
  sql,
143
146
  });
147
+ }
144
148
  const typeMap = options?.typeMap || GlobalTypeMap;
145
149
  const paramTypes = options?.params?.map(prm => prm instanceof BindParam ? prm.oid : typeMap.determine(prm));
146
150
  const statement = await this.prepare(sql, { paramTypes, typeMap }).catch((e) => {
@@ -161,13 +165,14 @@ export class Connection extends SafeEventEmitter {
161
165
  */
162
166
  async prepare(sql, options) {
163
167
  /* istanbul ignore next */
164
- if (this.listenerCount('debug'))
168
+ if (this.listenerCount('debug')) {
165
169
  this.emit('debug', {
166
170
  location: 'Connection.prepare',
167
171
  connection: this,
168
172
  message: `[${this.processID}] prepare | ${sql}`,
169
173
  sql,
170
174
  });
175
+ }
171
176
  return await this._captureErrorStack(PreparedStatement.prepare(this, sql, options));
172
177
  }
173
178
  /**
@@ -109,8 +109,9 @@ export class IntlConnection extends SafeEventEmitter {
109
109
  const result = await this._execute(sql, options, cb);
110
110
  if (commitLast)
111
111
  await this._execute('COMMIT');
112
- else if (this.inTransaction && rollbackOnError)
112
+ else if (this.inTransaction && rollbackOnError) {
113
113
  await this._execute('RELEASE ' + this._onErrorSavePoint + ';');
114
+ }
114
115
  return result;
115
116
  }
116
117
  catch (e) {
@@ -191,20 +192,23 @@ export class IntlConnection extends SafeEventEmitter {
191
192
  current.rows = [];
192
193
  break;
193
194
  case Protocol.BackendMessageCode.DataRow:
194
- let row = msg.columns.map((x) => x.toString('utf8'));
195
- parseRow(parsers, row, opts);
196
- if (opts.objectRows && current.fields)
197
- row = convertRowToObject(current.fields, row);
198
- if (cb)
199
- cb('row', row);
200
- current.rows = current.rows || [];
201
- current.rows.push(row);
195
+ {
196
+ let row = msg.columns.map((x) => x.toString('utf8'));
197
+ parseRow(parsers, row, opts);
198
+ if (opts.objectRows && current.fields)
199
+ row = convertRowToObject(current.fields, row);
200
+ if (cb)
201
+ cb('row', row);
202
+ current.rows = current.rows || [];
203
+ current.rows.push(row);
204
+ }
202
205
  break;
203
206
  case Protocol.BackendMessageCode.CommandComplete:
204
207
  // Ignore BEGIN command that we added to sql
205
208
  current.command = msg.command;
206
- if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE')
209
+ if (current.command === 'DELETE' || current.command === 'INSERT' || current.command === 'UPDATE') {
207
210
  current.rowsAffected = msg.rowCount;
211
+ }
208
212
  current.executeTime = Date.now() - currentStart;
209
213
  if (current.rows)
210
214
  current.rowType = opts.objectRows && current.fields ? 'object' : 'array';
@@ -220,6 +224,9 @@ export class IntlConnection extends SafeEventEmitter {
220
224
  // Ignore COMMIT command that we added to sql
221
225
  result.totalCommands = result.results.length;
222
226
  done(undefined, result);
227
+ break;
228
+ default:
229
+ break;
223
230
  }
224
231
  });
225
232
  }
@@ -25,42 +25,46 @@ export class Pool extends SafeEventEmitter {
25
25
  const poolFactory = {
26
26
  create: async () => {
27
27
  /* istanbul ignore next */
28
- if (this.listenerCount('debug'))
28
+ if (this.listenerCount('debug')) {
29
29
  this.emit('debug', {
30
30
  location: 'Pool.factory.create',
31
31
  pool: this,
32
32
  message: `new connection creating`,
33
33
  });
34
+ }
34
35
  const intlCon = new IntlConnection(cfg);
35
36
  await intlCon.connect();
36
37
  intlCon.on('close', () => this._pool.destroy(intlCon));
37
38
  /* istanbul ignore next */
38
- if (this.listenerCount('debug'))
39
+ if (this.listenerCount('debug')) {
39
40
  this.emit('debug', {
40
41
  location: 'Pool.factory.create',
41
42
  pool: this,
42
43
  message: `[${intlCon.processID}] connection created`,
43
44
  });
45
+ }
44
46
  return intlCon;
45
47
  },
46
48
  destroy: intlCon => {
47
49
  /* istanbul ignore next */
48
- if (this.listenerCount('debug'))
50
+ if (this.listenerCount('debug')) {
49
51
  this.emit('debug', {
50
52
  location: 'Pool.factory.destroy',
51
53
  pool: this,
52
54
  message: `[${intlCon.processID}] connection destroy`,
53
55
  });
56
+ }
54
57
  return intlCon.close();
55
58
  },
56
59
  reset: async (intlCon) => {
57
60
  /* istanbul ignore next */
58
- if (this.listenerCount('debug'))
61
+ if (this.listenerCount('debug')) {
59
62
  this.emit('debug', {
60
63
  location: 'Pool.factory.reset',
61
64
  pool: this,
62
65
  message: `[${intlCon.processID}] connection reset`,
63
66
  });
67
+ }
64
68
  try {
65
69
  if (intlCon.state === ConnectionState.READY) {
66
70
  await intlCon.execute('ROLLBACK;UNLISTEN *');
@@ -74,12 +78,13 @@ export class Pool extends SafeEventEmitter {
74
78
  },
75
79
  validate: async (intlCon) => {
76
80
  /* istanbul ignore next */
77
- if (this.listenerCount('debug'))
81
+ if (this.listenerCount('debug')) {
78
82
  this.emit('debug', {
79
83
  location: 'Pool.factory.validate',
80
84
  pool: this,
81
85
  message: `[${intlCon.processID}] connection validate`,
82
86
  });
87
+ }
83
88
  if (intlCon.state !== ConnectionState.READY)
84
89
  throw new Error('Connection is not active');
85
90
  await intlCon.execute('select 1;');
@@ -116,12 +121,13 @@ export class Pool extends SafeEventEmitter {
116
121
  async acquire() {
117
122
  const intlCon = await this._pool.acquire();
118
123
  /* istanbul ignore next */
119
- if (this.listenerCount('debug'))
124
+ if (this.listenerCount('debug')) {
120
125
  this.emit('debug', {
121
126
  location: 'Pool.acquire',
122
127
  pool: this,
123
128
  message: `[${intlCon.processID}] acquired`,
124
129
  });
130
+ }
125
131
  const connection = new Connection(this, intlCon);
126
132
  /* istanbul ignore next */
127
133
  if (this.listenerCount('debug'))
@@ -100,13 +100,15 @@ export class PreparedStatement extends SafeEventEmitter {
100
100
  const result = await intlCon.statementQueue.enqueue(() => this._execute(options)).toPromise();
101
101
  if (commitLast)
102
102
  await intlCon.execute('COMMIT');
103
- else if (intlCon.inTransaction && rollbackOnError)
103
+ else if (intlCon.inTransaction && rollbackOnError) {
104
104
  await intlCon.execute('RELEASE ' + this._onErrorSavePoint + ';');
105
+ }
105
106
  return result;
106
107
  }
107
108
  catch (e) {
108
- if (intlCon.inTransaction && rollbackOnError)
109
+ if (intlCon.inTransaction && rollbackOnError) {
109
110
  await intlCon.execute('ROLLBACK TO ' + this._onErrorSavePoint + ';');
111
+ }
110
112
  throw e;
111
113
  }
112
114
  }
@@ -166,8 +168,9 @@ export class PreparedStatement extends SafeEventEmitter {
166
168
  }
167
169
  }
168
170
  }
169
- if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE')
171
+ if (result.command === 'DELETE' || result.command === 'INSERT' || result.command === 'UPDATE') {
170
172
  result.rowsAffected = executeResult.rowCount;
173
+ }
171
174
  result.executeTime = Date.now() - startTime;
172
175
  return result;
173
176
  }
@@ -10,8 +10,9 @@ export const TimeType = {
10
10
  const hi = v.readInt32BE();
11
11
  const lo = v.readUInt32BE(4);
12
12
  let d = new Date((lo + hi * timeMul) / 1000);
13
- if (fetchAsString || !options.utcDates)
13
+ if (fetchAsString || !options.utcDates) {
14
14
  d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
15
+ }
15
16
  return fetchAsString ? dateToTimeString(d) : d;
16
17
  },
17
18
  encodeBinary(buf, v, options) {
@@ -16,8 +16,9 @@ export const TimestampType = {
16
16
  return fetchAsString ? '-infinity' : -Infinity;
17
17
  // Shift from 2000 to 1970
18
18
  let d = new Date((lo + hi * timeMul) / 1000 + timeShift);
19
- if (fetchAsString || !options.utcDates)
19
+ if (fetchAsString || !options.utcDates) {
20
20
  d = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
21
+ }
21
22
  return fetchAsString ? dateToTimestampString(d) : d;
22
23
  },
23
24
  encodeBinary(buf, v, options) {