postgrejs 2.22.2 → 2.22.4
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.
- package/CHANGELOG.md +518 -588
- package/cjs/connection/connection.js +9 -4
- package/cjs/connection/intl-connection.js +12 -5
- package/cjs/connection/portal.js +10 -3
- package/cjs/connection/prepared-statement.js +9 -3
- package/cjs/constants.js +0 -1
- package/cjs/data-type-map.js +15 -3
- package/cjs/data-types/bool-type.js +7 -1
- package/cjs/data-types/circle-type.js +4 -1
- package/cjs/data-types/date-type.js +12 -4
- package/cjs/data-types/int2-type.js +1 -1
- package/cjs/data-types/int2-vector-type.js +5 -1
- package/cjs/data-types/int4-type.js +3 -1
- package/cjs/data-types/int8-type.js +7 -2
- package/cjs/data-types/json-type.js +4 -2
- package/cjs/data-types/jsonb-type.js +4 -2
- package/cjs/data-types/lseg-type.js +4 -1
- package/cjs/data-types/point-type.js +4 -1
- package/cjs/data-types/time-type.js +16 -5
- package/cjs/data-types/timestamp-type.js +11 -4
- package/cjs/data-types/timestamptz-type.js +4 -2
- package/cjs/protocol/backend.js +9 -3
- package/cjs/protocol/frontend.js +40 -10
- package/cjs/protocol/pg-socket.js +5 -2
- package/cjs/protocol/sasl.js +2 -2
- package/cjs/protocol/smart-buffer.js +1 -2
- package/cjs/safe-event-emitter.js +1 -1
- package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
- package/cjs/util/bigint-methods.js +5 -2
- package/cjs/util/connection-config.js +5 -6
- package/cjs/util/parse-datetime.js +4 -4
- package/cjs/util/parse-row.js +2 -1
- package/cjs/util/parse-time.js +3 -2
- package/esm/connection/connection.js +9 -4
- package/esm/connection/intl-connection.js +12 -5
- package/esm/connection/pool.js +1 -1
- package/esm/connection/portal.js +10 -3
- package/esm/connection/prepared-statement.js +9 -3
- package/esm/constants.js +0 -1
- package/esm/data-type-map.js +18 -6
- package/esm/data-types/bool-type.js +7 -1
- package/esm/data-types/circle-type.js +4 -1
- package/esm/data-types/date-type.js +12 -4
- package/esm/data-types/int2-type.js +1 -1
- package/esm/data-types/int2-vector-type.js +5 -1
- package/esm/data-types/int4-type.js +3 -1
- package/esm/data-types/int8-type.js +7 -2
- package/esm/data-types/json-type.js +4 -2
- package/esm/data-types/jsonb-type.js +4 -2
- package/esm/data-types/lseg-type.js +4 -1
- package/esm/data-types/point-type.js +4 -1
- package/esm/data-types/time-type.js +16 -5
- package/esm/data-types/timestamp-type.js +11 -4
- package/esm/data-types/timestamptz-type.js +4 -2
- package/esm/protocol/backend.js +9 -3
- package/esm/protocol/frontend.js +40 -10
- package/esm/protocol/pg-socket.js +5 -2
- package/esm/protocol/sasl.js +2 -2
- package/esm/protocol/smart-buffer.js +1 -2
- package/esm/safe-event-emitter.js +1 -1
- package/esm/util/bigint-methods.js +5 -2
- package/esm/util/connection-config.js +2 -2
- package/esm/util/parse-datetime.js +4 -4
- package/esm/util/parse-row.js +2 -1
- package/esm/util/parse-time.js +3 -2
- package/package.json +8 -5
|
@@ -157,7 +157,8 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
157
157
|
this._send(this._frontend.getSyncMessage());
|
|
158
158
|
}
|
|
159
159
|
capture(callback) {
|
|
160
|
-
if (this._state === constants_js_1.ConnectionState.CLOSING ||
|
|
160
|
+
if (this._state === constants_js_1.ConnectionState.CLOSING ||
|
|
161
|
+
this._state === constants_js_1.ConnectionState.CLOSED) {
|
|
161
162
|
return Promise.reject(new Error('Connection closed'));
|
|
162
163
|
}
|
|
163
164
|
if (this._state !== constants_js_1.ConnectionState.READY)
|
|
@@ -279,7 +280,9 @@ class PgSocket extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
279
280
|
}
|
|
280
281
|
_resolvePassword(cb) {
|
|
281
282
|
(async () => {
|
|
282
|
-
const pass = typeof this.options.password === 'function'
|
|
283
|
+
const pass = typeof this.options.password === 'function'
|
|
284
|
+
? await this.options.password()
|
|
285
|
+
: this.options.password;
|
|
283
286
|
cb(pass || '');
|
|
284
287
|
})().catch(err => this._handleError(err));
|
|
285
288
|
}
|
package/cjs/protocol/sasl.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SASL = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable no-bitwise */
|
|
6
5
|
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
7
6
|
var SASL;
|
|
8
7
|
(function (SASL) {
|
|
@@ -61,7 +60,8 @@ var SASL;
|
|
|
61
60
|
const serverKey = hmac(saltPass, SERVER_KEY);
|
|
62
61
|
const serverSignatureBytes = hmac(serverKey, authMessage);
|
|
63
62
|
session.serverSignature = serverSignatureBytes.toString('base64');
|
|
64
|
-
session.clientFinalMessage =
|
|
63
|
+
session.clientFinalMessage =
|
|
64
|
+
clientFinalMessageWithoutProof + ',p=' + clientProof;
|
|
65
65
|
}
|
|
66
66
|
SASL.continueSession = continueSession;
|
|
67
67
|
function finalizeSession(session, data) {
|
|
@@ -7,8 +7,7 @@ const bigint_methods_js_1 = require("../util/bigint-methods.js");
|
|
|
7
7
|
const buffer_reader_js_1 = require("./buffer-reader.js");
|
|
8
8
|
class SmartBuffer extends buffer_reader_js_1.BufferReader {
|
|
9
9
|
constructor(cfg) {
|
|
10
|
-
|
|
11
|
-
super(Buffer.allocUnsafe((cfg?.pageSize ? parseInt(cfg.pageSize, 10) : 0) || SmartBuffer.DEFAULT_PAGE_SIZE));
|
|
10
|
+
super(Buffer.allocUnsafe(cfg?.pageSize || SmartBuffer.DEFAULT_PAGE_SIZE));
|
|
12
11
|
this._lastHouseKeep = 0;
|
|
13
12
|
this._stMaxPages = 1;
|
|
14
13
|
this._length = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/constants.ts","../../src/data-type-map.ts","../../src/index.ts","../../src/safe-event-emitter.ts","../../src/types.ts","../../src/connection/bind-param.ts","../../src/connection/connection.ts","../../src/connection/cursor.ts","../../src/connection/intl-connection.ts","../../src/connection/pool.ts","../../src/connection/portal.ts","../../src/connection/prepared-statement.ts","../../src/data-types/bool-type.ts","../../src/data-types/box-type.ts","../../src/data-types/bytea-type.ts","../../src/data-types/char-type.ts","../../src/data-types/circle-type.ts","../../src/data-types/date-type.ts","../../src/data-types/float4-type.ts","../../src/data-types/float8-type.ts","../../src/data-types/int2-type.ts","../../src/data-types/int2-vector-type.ts","../../src/data-types/int4-type.ts","../../src/data-types/int8-type.ts","../../src/data-types/json-type.ts","../../src/data-types/jsonb-type.ts","../../src/data-types/lseg-type.ts","../../src/data-types/numeric-type.ts","../../src/data-types/oid-type.ts","../../src/data-types/point-type.ts","../../src/data-types/time-type.ts","../../src/data-types/timestamp-type.ts","../../src/data-types/timestamptz-type.ts","../../src/data-types/uuid-type.ts","../../src/data-types/varchar-type.ts","../../src/interfaces/command-result.ts","../../src/interfaces/data-mapping-options.ts","../../src/interfaces/data-type.ts","../../src/interfaces/database-connection-params.ts","../../src/interfaces/field-info.ts","../../src/interfaces/query-options.ts","../../src/interfaces/query-result.ts","../../src/interfaces/script-execute-options.ts","../../src/interfaces/script-result.ts","../../src/interfaces/statement-prepare-options.ts","../../src/protocol/backend.ts","../../src/protocol/buffer-reader.ts","../../src/protocol/database-error.ts","../../src/protocol/frontend.ts","../../src/protocol/pg-socket.ts","../../src/protocol/protocol.ts","../../src/protocol/sasl.ts","../../src/protocol/smart-buffer.ts","../../src/util/array-calculatedim.ts","../../src/util/bigint-methods.ts","../../src/util/config-from-env.ts","../../src/util/connection-config.ts","../../src/util/convert-row-to-object.ts","../../src/util/decode-binaryarray.ts","../../src/util/encode-binaryarray.ts","../../src/util/escape-literal.ts","../../src/util/fast-parseint.ts","../../src/util/get-parsers.ts","../../src/util/parse-array.ts","../../src/util/parse-datetime.ts","../../src/util/parse-row.ts","../../src/util/parse-time.ts","../../src/util/stringify-arrayliteral.ts","../../src/util/stringify-for-sql.ts","../../src/util/wrap-row-description.ts"],"version":"5.
|
|
1
|
+
{"root":["../../src/constants.ts","../../src/data-type-map.ts","../../src/index.ts","../../src/safe-event-emitter.ts","../../src/types.ts","../../src/connection/bind-param.ts","../../src/connection/connection.ts","../../src/connection/cursor.ts","../../src/connection/intl-connection.ts","../../src/connection/pool.ts","../../src/connection/portal.ts","../../src/connection/prepared-statement.ts","../../src/data-types/bool-type.ts","../../src/data-types/box-type.ts","../../src/data-types/bytea-type.ts","../../src/data-types/char-type.ts","../../src/data-types/circle-type.ts","../../src/data-types/date-type.ts","../../src/data-types/float4-type.ts","../../src/data-types/float8-type.ts","../../src/data-types/int2-type.ts","../../src/data-types/int2-vector-type.ts","../../src/data-types/int4-type.ts","../../src/data-types/int8-type.ts","../../src/data-types/json-type.ts","../../src/data-types/jsonb-type.ts","../../src/data-types/lseg-type.ts","../../src/data-types/numeric-type.ts","../../src/data-types/oid-type.ts","../../src/data-types/point-type.ts","../../src/data-types/time-type.ts","../../src/data-types/timestamp-type.ts","../../src/data-types/timestamptz-type.ts","../../src/data-types/uuid-type.ts","../../src/data-types/varchar-type.ts","../../src/interfaces/command-result.ts","../../src/interfaces/data-mapping-options.ts","../../src/interfaces/data-type.ts","../../src/interfaces/database-connection-params.ts","../../src/interfaces/field-info.ts","../../src/interfaces/query-options.ts","../../src/interfaces/query-result.ts","../../src/interfaces/script-execute-options.ts","../../src/interfaces/script-result.ts","../../src/interfaces/statement-prepare-options.ts","../../src/protocol/backend.ts","../../src/protocol/buffer-reader.ts","../../src/protocol/database-error.ts","../../src/protocol/frontend.ts","../../src/protocol/pg-socket.ts","../../src/protocol/protocol.ts","../../src/protocol/sasl.ts","../../src/protocol/smart-buffer.ts","../../src/util/array-calculatedim.ts","../../src/util/bigint-methods.ts","../../src/util/config-from-env.ts","../../src/util/connection-config.ts","../../src/util/convert-row-to-object.ts","../../src/util/decode-binaryarray.ts","../../src/util/encode-binaryarray.ts","../../src/util/escape-literal.ts","../../src/util/fast-parseint.ts","../../src/util/get-parsers.ts","../../src/util/parse-array.ts","../../src/util/parse-datetime.ts","../../src/util/parse-row.ts","../../src/util/parse-time.ts","../../src/util/stringify-arrayliteral.ts","../../src/util/stringify-for-sql.ts","../../src/util/wrap-row-description.ts"],"version":"5.8.3"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readBigInt64BE = readBigInt64BE;
|
|
4
4
|
exports.writeBigUInt64BE = writeBigUInt64BE;
|
|
5
|
-
/* eslint-disable no-bitwise */
|
|
6
5
|
const big0 = BigInt(0);
|
|
7
6
|
const beAnd = BigInt('0xffffffff');
|
|
8
7
|
const big32 = BigInt(32);
|
|
@@ -16,7 +15,11 @@ function readBigInt64BE(buf, offset = 0) {
|
|
|
16
15
|
buf[++offset] * 2 ** 16 +
|
|
17
16
|
buf[++offset] * 2 ** 8 +
|
|
18
17
|
buf[++offset];
|
|
19
|
-
return ((BigInt(val) << big32) +
|
|
18
|
+
return ((BigInt(val) << big32) +
|
|
19
|
+
BigInt(buf[++offset] * 2 ** 24 +
|
|
20
|
+
buf[++offset] * 2 ** 16 +
|
|
21
|
+
buf[++offset] * 2 ** 8 +
|
|
22
|
+
last));
|
|
20
23
|
}
|
|
21
24
|
function writeBigUInt64BE(buf, value, offset = 0) {
|
|
22
25
|
// @ts-ignore
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getConnectionConfig = getConnectionConfig;
|
|
4
4
|
exports.parseConnectionString = parseConnectionString;
|
|
5
|
-
const
|
|
6
|
-
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
5
|
+
const objects_1 = require("@jsopen/objects");
|
|
7
6
|
const config_from_env_js_1 = require("./config-from-env.js");
|
|
8
7
|
function getConnectionConfig(config) {
|
|
9
8
|
const cfg = (0, config_from_env_js_1.configFromEnv)();
|
|
10
9
|
if (typeof config === 'string') {
|
|
11
|
-
(0,
|
|
10
|
+
(0, objects_1.merge)(cfg, parseConnectionString(config));
|
|
12
11
|
}
|
|
13
12
|
else if (typeof config === 'object') {
|
|
14
|
-
(0,
|
|
13
|
+
(0, objects_1.merge)(cfg, config);
|
|
15
14
|
}
|
|
16
15
|
if (cfg.host) {
|
|
17
16
|
const x = parseConnectionString('' + cfg.host);
|
|
18
|
-
(0,
|
|
17
|
+
(0, objects_1.merge)(cfg, x);
|
|
19
18
|
}
|
|
20
19
|
cfg.user = cfg.user || 'postgres';
|
|
21
20
|
cfg.database = cfg.database || 'postgres';
|
|
@@ -28,7 +27,7 @@ function parseConnectionString(str) {
|
|
|
28
27
|
if (!str.includes('://'))
|
|
29
28
|
str = 'postgres://' + str;
|
|
30
29
|
const parsed = new URL(str);
|
|
31
|
-
const getFirst = (v) =>
|
|
30
|
+
const getFirst = (v) => typeof v === 'string' ? v : Array.isArray(v) ? v[0] : '';
|
|
32
31
|
const cfg = {};
|
|
33
32
|
cfg.host = decodeURI(parsed.hostname || '');
|
|
34
33
|
if (parsed.port)
|
|
@@ -4,9 +4,7 @@ exports.parseDateTime = parseDateTime;
|
|
|
4
4
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
5
5
|
const fast_parseint_js_1 = require("./fast-parseint.js");
|
|
6
6
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
7
|
-
const TIMESTAMP_PATTERN =
|
|
8
|
-
// eslint-disable-next-line
|
|
9
|
-
/^(\d{4})-?(0[1-9]|1[012])?-?([123]0|[012][1-9]|31)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
|
|
7
|
+
const TIMESTAMP_PATTERN = /^(\d{4})-?(0[1-9]|1[012])?-?([123]0|[012][1-9]|31)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
|
|
10
8
|
const INFINITY_PATTERN = /^-?infinity$/;
|
|
11
9
|
function parseDateTime(str, parseTime, parseTimeZone, utc) {
|
|
12
10
|
let m = str.match(TIMESTAMP_PATTERN);
|
|
@@ -16,7 +14,9 @@ function parseDateTime(str, parseTime, parseTimeZone, utc) {
|
|
|
16
14
|
return Number(str.replace('i', 'I'));
|
|
17
15
|
return new Date('invalid');
|
|
18
16
|
}
|
|
19
|
-
const args = [
|
|
17
|
+
const args = [
|
|
18
|
+
1970, 0, 1, 0, 0, 0, 0,
|
|
19
|
+
];
|
|
20
20
|
const l = parseTime ? 7 : 3;
|
|
21
21
|
for (let i = 0; i < l; i++) {
|
|
22
22
|
const s = m[i + 1];
|
package/cjs/util/parse-row.js
CHANGED
|
@@ -5,6 +5,7 @@ function parseRow(parsers, row, options) {
|
|
|
5
5
|
const l = row.length;
|
|
6
6
|
let i;
|
|
7
7
|
for (i = 0; i < l; i++) {
|
|
8
|
-
row[i] =
|
|
8
|
+
row[i] =
|
|
9
|
+
row[i] == null ? null : parsers[i].call(undefined, row[i], options);
|
|
9
10
|
}
|
|
10
11
|
}
|
package/cjs/util/parse-time.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TIME_PATTERN = exports.STRICT_TIME_PATTERN = void 0;
|
|
4
4
|
exports.parseTime = parseTime;
|
|
5
5
|
const fast_parseint_js_1 = require("./fast-parseint.js");
|
|
6
|
-
// eslint-disable-next-line
|
|
7
6
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
8
7
|
exports.STRICT_TIME_PATTERN = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?$/;
|
|
9
8
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
@@ -12,7 +11,9 @@ function parseTime(str, parseTimeZone, utc) {
|
|
|
12
11
|
const m = str.match(exports.TIME_PATTERN);
|
|
13
12
|
if (!m)
|
|
14
13
|
return new Date('invalid');
|
|
15
|
-
const args = [
|
|
14
|
+
const args = [
|
|
15
|
+
1970, 0, 1, 0, 0, 0, 0,
|
|
16
|
+
];
|
|
16
17
|
for (let i = 1; i < 4; i++) {
|
|
17
18
|
const s = m[i];
|
|
18
19
|
args[i + 2] = (0, fast_parseint_js_1.fastParseInt)(s) || 0;
|
|
@@ -9,7 +9,9 @@ export class Connection extends SafeEventEmitter {
|
|
|
9
9
|
super();
|
|
10
10
|
this._notificationListeners = new SafeEventEmitter();
|
|
11
11
|
this._closing = false;
|
|
12
|
-
if (arg0 &&
|
|
12
|
+
if (arg0 &&
|
|
13
|
+
typeof arg0 === 'object' &&
|
|
14
|
+
typeof arg0.acquire === 'function') {
|
|
13
15
|
if (!(arg1 instanceof IntlConnection))
|
|
14
16
|
throw new TypeError('Invalid argument');
|
|
15
17
|
this._pool = arg0;
|
|
@@ -91,7 +93,9 @@ export class Connection extends SafeEventEmitter {
|
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
95
|
this._closing = true;
|
|
94
|
-
if (this._intlCon.refCount > 0 &&
|
|
96
|
+
if (this._intlCon.refCount > 0 &&
|
|
97
|
+
typeof terminateWait === 'number' &&
|
|
98
|
+
terminateWait > 0) {
|
|
95
99
|
const startTime = Date.now();
|
|
96
100
|
return this._captureErrorStack(new Promise((resolve, reject) => {
|
|
97
101
|
/* istanbul ignore next */
|
|
@@ -103,7 +107,8 @@ export class Connection extends SafeEventEmitter {
|
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
const timer = setInterval(() => {
|
|
106
|
-
if (this._intlCon.refCount <= 0 ||
|
|
110
|
+
if (this._intlCon.refCount <= 0 ||
|
|
111
|
+
Date.now() > startTime + terminateWait) {
|
|
107
112
|
clearInterval(timer);
|
|
108
113
|
if (this._intlCon.refCount > 0) {
|
|
109
114
|
/* istanbul ignore next */
|
|
@@ -153,7 +158,7 @@ export class Connection extends SafeEventEmitter {
|
|
|
153
158
|
throw this._handleError(e, sql);
|
|
154
159
|
});
|
|
155
160
|
try {
|
|
156
|
-
const params = options?.params?.map(prm =>
|
|
161
|
+
const params = options?.params?.map(prm => prm instanceof BindParam ? prm.value : prm);
|
|
157
162
|
return await this._captureErrorStack(statement.execute({ ...options, params }));
|
|
158
163
|
}
|
|
159
164
|
finally {
|
|
@@ -61,9 +61,11 @@ export class IntlConnection extends SafeEventEmitter {
|
|
|
61
61
|
});
|
|
62
62
|
let startupCommand = '';
|
|
63
63
|
if (this.config.schema)
|
|
64
|
-
startupCommand +=
|
|
64
|
+
startupCommand +=
|
|
65
|
+
'SET search_path = ' + escapeLiteral(this.config.schema) + ';';
|
|
65
66
|
if (this.config.timezone)
|
|
66
|
-
startupCommand +=
|
|
67
|
+
startupCommand +=
|
|
68
|
+
'SET timezone TO ' + escapeLiteral(this.config.timezone) + ';';
|
|
67
69
|
if (startupCommand)
|
|
68
70
|
await this.execute(startupCommand, { autoCommit: true });
|
|
69
71
|
this.emit('ready');
|
|
@@ -91,7 +93,9 @@ export class IntlConnection extends SafeEventEmitter {
|
|
|
91
93
|
let commitLast = false;
|
|
92
94
|
if (!transactionCommand) {
|
|
93
95
|
if (!this.inTransaction &&
|
|
94
|
-
(options?.autoCommit != null
|
|
96
|
+
(options?.autoCommit != null
|
|
97
|
+
? options?.autoCommit
|
|
98
|
+
: this.config.autoCommit) === false) {
|
|
95
99
|
beginFirst = true;
|
|
96
100
|
}
|
|
97
101
|
if (this.inTransaction && options?.autoCommit)
|
|
@@ -207,12 +211,15 @@ export class IntlConnection extends SafeEventEmitter {
|
|
|
207
211
|
case Protocol.BackendMessageCode.CommandComplete:
|
|
208
212
|
// Ignore BEGIN command that we added to sql
|
|
209
213
|
current.command = msg.command;
|
|
210
|
-
if (current.command === 'DELETE' ||
|
|
214
|
+
if (current.command === 'DELETE' ||
|
|
215
|
+
current.command === 'INSERT' ||
|
|
216
|
+
current.command === 'UPDATE') {
|
|
211
217
|
current.rowsAffected = msg.rowCount;
|
|
212
218
|
}
|
|
213
219
|
current.executeTime = Date.now() - currentStart;
|
|
214
220
|
if (current.rows)
|
|
215
|
-
current.rowType =
|
|
221
|
+
current.rowType =
|
|
222
|
+
opts.objectRows && current.fields ? 'object' : 'array';
|
|
216
223
|
result.results.push(current);
|
|
217
224
|
if (cb)
|
|
218
225
|
cb('command-complete', current);
|
package/esm/connection/pool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Pool as LightningPool } from 'lightning-pool';
|
|
1
|
+
import { Pool as LightningPool, } from 'lightning-pool';
|
|
2
2
|
import { coerceToBoolean, coerceToInt } from 'putil-varhelpers';
|
|
3
3
|
import { ConnectionState } from '../constants.js';
|
|
4
4
|
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
package/esm/connection/portal.js
CHANGED
|
@@ -19,7 +19,10 @@ export class Portal {
|
|
|
19
19
|
intoCon.ref();
|
|
20
20
|
try {
|
|
21
21
|
const socket = intoCon.socket;
|
|
22
|
-
this._columnFormat =
|
|
22
|
+
this._columnFormat =
|
|
23
|
+
queryOptions.columnFormat != null
|
|
24
|
+
? queryOptions.columnFormat
|
|
25
|
+
: Protocol.DataFormat.binary;
|
|
23
26
|
socket.sendBindMessage({
|
|
24
27
|
typeMap: queryOptions.typeMap || GlobalTypeMap,
|
|
25
28
|
statement: this._statement.name,
|
|
@@ -76,7 +79,10 @@ export class Portal {
|
|
|
76
79
|
intoCon.ref();
|
|
77
80
|
try {
|
|
78
81
|
const socket = intoCon.socket;
|
|
79
|
-
socket.sendExecuteMessage({
|
|
82
|
+
socket.sendExecuteMessage({
|
|
83
|
+
portal: this.name,
|
|
84
|
+
fetchCount: fetchCount || 100,
|
|
85
|
+
});
|
|
80
86
|
socket.sendFlushMessage();
|
|
81
87
|
const rows = [];
|
|
82
88
|
return await socket.capture(async (code, msg, done) => {
|
|
@@ -88,7 +94,8 @@ export class Portal {
|
|
|
88
94
|
break;
|
|
89
95
|
case Protocol.BackendMessageCode.DataRow:
|
|
90
96
|
if (Array.isArray(this._columnFormat)) {
|
|
91
|
-
rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
|
|
97
|
+
rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
|
|
98
|
+
Protocol.DataFormat.text
|
|
92
99
|
? buf.toString('utf8')
|
|
93
100
|
: buf));
|
|
94
101
|
}
|
|
@@ -82,7 +82,9 @@ export class PreparedStatement extends SafeEventEmitter {
|
|
|
82
82
|
let commitLast = false;
|
|
83
83
|
if (!transactionCommand) {
|
|
84
84
|
if (!intlCon.inTransaction &&
|
|
85
|
-
(options?.autoCommit != null
|
|
85
|
+
(options?.autoCommit != null
|
|
86
|
+
? options?.autoCommit
|
|
87
|
+
: intlCon.config.autoCommit) === false) {
|
|
86
88
|
beginFirst = true;
|
|
87
89
|
}
|
|
88
90
|
if (intlCon.inTransaction && options?.autoCommit)
|
|
@@ -97,7 +99,9 @@ export class PreparedStatement extends SafeEventEmitter {
|
|
|
97
99
|
if (intlCon.inTransaction && rollbackOnError)
|
|
98
100
|
await intlCon.execute('SAVEPOINT ' + this._onErrorSavePoint);
|
|
99
101
|
try {
|
|
100
|
-
const result = await intlCon.statementQueue
|
|
102
|
+
const result = await intlCon.statementQueue
|
|
103
|
+
.enqueue(() => this._execute(options))
|
|
104
|
+
.toPromise();
|
|
101
105
|
if (commitLast)
|
|
102
106
|
await intlCon.execute('COMMIT');
|
|
103
107
|
else if (intlCon.inTransaction && rollbackOnError) {
|
|
@@ -168,7 +172,9 @@ export class PreparedStatement extends SafeEventEmitter {
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
}
|
|
171
|
-
if (result.command === 'DELETE' ||
|
|
175
|
+
if (result.command === 'DELETE' ||
|
|
176
|
+
result.command === 'INSERT' ||
|
|
177
|
+
result.command === 'UPDATE') {
|
|
172
178
|
result.rowsAffected = executeResult.rowCount;
|
|
173
179
|
}
|
|
174
180
|
result.executeTime = Date.now() - startTime;
|
package/esm/constants.js
CHANGED
package/esm/data-type-map.js
CHANGED
|
@@ -8,7 +8,7 @@ import { ArrayDateType, DateType } from './data-types/date-type.js';
|
|
|
8
8
|
import { ArrayFloat4Type, Float4Type } from './data-types/float4-type.js';
|
|
9
9
|
import { ArrayFloat8Type, Float8Type } from './data-types/float8-type.js';
|
|
10
10
|
import { ArrayInt2Type, Int2Type } from './data-types/int2-type.js';
|
|
11
|
-
import { ArrayInt2VectorType, Int2VectorType } from './data-types/int2-vector-type.js';
|
|
11
|
+
import { ArrayInt2VectorType, Int2VectorType, } from './data-types/int2-vector-type.js';
|
|
12
12
|
import { ArrayInt4Type, Int4Type } from './data-types/int4-type.js';
|
|
13
13
|
import { ArrayInt8Type, Int8Type } from './data-types/int8-type.js';
|
|
14
14
|
import { ArrayJsonType, JsonType } from './data-types/json-type.js';
|
|
@@ -18,8 +18,8 @@ import { ArrayNumericType, NumericType } from './data-types/numeric-type.js';
|
|
|
18
18
|
import { ArrayOidType, OidType, VectorOidType } from './data-types/oid-type.js';
|
|
19
19
|
import { ArrayPointType, PointType } from './data-types/point-type.js';
|
|
20
20
|
import { ArrayTimeType, TimeType } from './data-types/time-type.js';
|
|
21
|
-
import { ArrayTimestampType, TimestampType } from './data-types/timestamp-type.js';
|
|
22
|
-
import { ArrayTimestamptzType, TimestamptzType } from './data-types/timestamptz-type.js';
|
|
21
|
+
import { ArrayTimestampType, TimestampType, } from './data-types/timestamp-type.js';
|
|
22
|
+
import { ArrayTimestamptzType, TimestamptzType, } from './data-types/timestamptz-type.js';
|
|
23
23
|
import { ArrayUuidType, UuidType } from './data-types/uuid-type.js';
|
|
24
24
|
import { ArrayVarcharType, VarcharType } from './data-types/varchar-type.js';
|
|
25
25
|
export class DataTypeMap {
|
|
@@ -78,21 +78,33 @@ GlobalTypeMap.register([PointType, ArrayPointType]);
|
|
|
78
78
|
GlobalTypeMap.register([LsegType, ArrayLsegType]);
|
|
79
79
|
GlobalTypeMap.register([BoxType, ArrayBoxType]);
|
|
80
80
|
GlobalTypeMap.register([Int2VectorType, ArrayInt2VectorType]);
|
|
81
|
-
GlobalTypeMap.register({
|
|
81
|
+
GlobalTypeMap.register({
|
|
82
|
+
...VarcharType,
|
|
83
|
+
name: 'bpchar',
|
|
84
|
+
oid: DataTypeOIDs.bpchar,
|
|
85
|
+
});
|
|
82
86
|
GlobalTypeMap.register({
|
|
83
87
|
...ArrayVarcharType,
|
|
84
88
|
name: '_bpchar',
|
|
85
89
|
oid: DataTypeOIDs._bpchar,
|
|
86
90
|
elementsOID: DataTypeOIDs.bpchar,
|
|
87
91
|
});
|
|
88
|
-
GlobalTypeMap.register({
|
|
92
|
+
GlobalTypeMap.register({
|
|
93
|
+
...VarcharType,
|
|
94
|
+
name: 'name',
|
|
95
|
+
oid: DataTypeOIDs.name,
|
|
96
|
+
});
|
|
89
97
|
GlobalTypeMap.register({
|
|
90
98
|
...ArrayVarcharType,
|
|
91
99
|
name: '_name',
|
|
92
100
|
oid: DataTypeOIDs._name,
|
|
93
101
|
elementsOID: DataTypeOIDs.name,
|
|
94
102
|
});
|
|
95
|
-
GlobalTypeMap.register({
|
|
103
|
+
GlobalTypeMap.register({
|
|
104
|
+
...VarcharType,
|
|
105
|
+
name: 'text',
|
|
106
|
+
oid: DataTypeOIDs.text,
|
|
107
|
+
});
|
|
96
108
|
GlobalTypeMap.register({
|
|
97
109
|
...ArrayVarcharType,
|
|
98
110
|
name: '_text',
|
|
@@ -10,7 +10,13 @@ export const BoolType = {
|
|
|
10
10
|
buf.writeInt8(v ? 1 : 0);
|
|
11
11
|
},
|
|
12
12
|
parseText(v) {
|
|
13
|
-
return v === 'TRUE' ||
|
|
13
|
+
return (v === 'TRUE' ||
|
|
14
|
+
v === 't' ||
|
|
15
|
+
v === 'true' ||
|
|
16
|
+
v === 'y' ||
|
|
17
|
+
v === 'yes' ||
|
|
18
|
+
v === 'on' ||
|
|
19
|
+
v === '1');
|
|
14
20
|
},
|
|
15
21
|
isType(v) {
|
|
16
22
|
return typeof v === 'boolean';
|
|
@@ -20,7 +20,10 @@ export const CircleType = {
|
|
|
20
20
|
buf.writeDoubleBE(v.r);
|
|
21
21
|
},
|
|
22
22
|
parseText(v) {
|
|
23
|
-
const m = v.match(CIRCLE_PATTERN1) ||
|
|
23
|
+
const m = v.match(CIRCLE_PATTERN1) ||
|
|
24
|
+
v.match(CIRCLE_PATTERN2) ||
|
|
25
|
+
v.match(CIRCLE_PATTERN3) ||
|
|
26
|
+
v.match(CIRCLE_PATTERN4);
|
|
24
27
|
if (!m)
|
|
25
28
|
return undefined;
|
|
26
29
|
return {
|
|
@@ -6,7 +6,8 @@ export const DateType = {
|
|
|
6
6
|
oid: DataTypeOIDs.date,
|
|
7
7
|
jsType: 'Date',
|
|
8
8
|
parseBinary(v, options) {
|
|
9
|
-
const fetchAsString = options.fetchAsString &&
|
|
9
|
+
const fetchAsString = options.fetchAsString &&
|
|
10
|
+
options.fetchAsString.includes(DataTypeOIDs.date);
|
|
10
11
|
const t = v.readInt32BE();
|
|
11
12
|
if (t === 0x7fffffff)
|
|
12
13
|
return fetchAsString ? 'infinity' : Infinity;
|
|
@@ -31,13 +32,16 @@ export const DateType = {
|
|
|
31
32
|
}
|
|
32
33
|
if (!(v instanceof Date))
|
|
33
34
|
v = new Date(v);
|
|
34
|
-
let n = options.utcDates
|
|
35
|
+
let n = options.utcDates
|
|
36
|
+
? v.getTime()
|
|
37
|
+
: v.getTime() - v.getTimezoneOffset() * 60 * 1000;
|
|
35
38
|
n = (n - timeShift) / 1000 / 86400;
|
|
36
39
|
const t = Math.trunc(n + Number.EPSILON);
|
|
37
40
|
buf.writeInt32BE(t);
|
|
38
41
|
},
|
|
39
42
|
parseText(v, options) {
|
|
40
|
-
const fetchAsString = options.fetchAsString &&
|
|
43
|
+
const fetchAsString = options.fetchAsString &&
|
|
44
|
+
options.fetchAsString.includes(DataTypeOIDs.date);
|
|
41
45
|
if (fetchAsString)
|
|
42
46
|
return v;
|
|
43
47
|
return parseDateTime(v, false, false, options.utcDates);
|
|
@@ -54,7 +58,11 @@ function padZero(v) {
|
|
|
54
58
|
return v < 9 ? '0' + v : '' + v;
|
|
55
59
|
}
|
|
56
60
|
function dateToDateString(d) {
|
|
57
|
-
return d.getFullYear() +
|
|
61
|
+
return (d.getFullYear() +
|
|
62
|
+
'-' +
|
|
63
|
+
padZero(d.getMonth() + 1) +
|
|
64
|
+
'-' +
|
|
65
|
+
padZero(d.getDate()));
|
|
58
66
|
}
|
|
59
67
|
export const ArrayDateType = {
|
|
60
68
|
...DateType,
|
|
@@ -12,7 +12,7 @@ export const Int2Type = {
|
|
|
12
12
|
},
|
|
13
13
|
parseText: fastParseInt,
|
|
14
14
|
isType(v) {
|
|
15
|
-
return typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767;
|
|
15
|
+
return (typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767);
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
18
|
export const ArrayInt2Type = {
|
|
@@ -24,7 +24,11 @@ export const Int2VectorType = {
|
|
|
24
24
|
return v.join(' ');
|
|
25
25
|
},
|
|
26
26
|
isType(v) {
|
|
27
|
-
return (Array.isArray(v) &&
|
|
27
|
+
return (Array.isArray(v) &&
|
|
28
|
+
!v.find(x => !(typeof x === 'number' &&
|
|
29
|
+
Number.isInteger(x) &&
|
|
30
|
+
x >= -32768 &&
|
|
31
|
+
x <= 32767)));
|
|
28
32
|
},
|
|
29
33
|
};
|
|
30
34
|
export const ArrayInt2VectorType = {
|
|
@@ -12,7 +12,9 @@ export const Int4Type = {
|
|
|
12
12
|
},
|
|
13
13
|
parseText: fastParseInt,
|
|
14
14
|
isType(v) {
|
|
15
|
-
return typeof v === 'number' &&
|
|
15
|
+
return (typeof v === 'number' &&
|
|
16
|
+
Number.isInteger(v) &&
|
|
17
|
+
v <= Number.MAX_SAFE_INTEGER);
|
|
16
18
|
},
|
|
17
19
|
};
|
|
18
20
|
export const ArrayInt4Type = {
|
|
@@ -6,7 +6,9 @@ export const Int8Type = {
|
|
|
6
6
|
oid: DataTypeOIDs.int8,
|
|
7
7
|
jsType: 'BigInt',
|
|
8
8
|
parseBinary(buf) {
|
|
9
|
-
const v = typeof buf.readBigInt64BE === 'function'
|
|
9
|
+
const v = typeof buf.readBigInt64BE === 'function'
|
|
10
|
+
? buf.readBigInt64BE(0)
|
|
11
|
+
: readBigInt64BE(buf);
|
|
10
12
|
return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
|
|
11
13
|
},
|
|
12
14
|
encodeBinary(buf, v) {
|
|
@@ -17,7 +19,10 @@ export const Int8Type = {
|
|
|
17
19
|
return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
|
|
18
20
|
},
|
|
19
21
|
isType(v) {
|
|
20
|
-
return typeof v === 'bigint' ||
|
|
22
|
+
return (typeof v === 'bigint' ||
|
|
23
|
+
(typeof v === 'number' &&
|
|
24
|
+
Number.isInteger(v) &&
|
|
25
|
+
v > Number.MAX_SAFE_INTEGER));
|
|
21
26
|
},
|
|
22
27
|
};
|
|
23
28
|
export const ArrayInt8Type = {
|
|
@@ -5,7 +5,8 @@ export const JsonType = {
|
|
|
5
5
|
jsType: 'string',
|
|
6
6
|
parseBinary(v, options) {
|
|
7
7
|
const content = v.toString('utf8');
|
|
8
|
-
const fetchAsString = options.fetchAsString &&
|
|
8
|
+
const fetchAsString = options.fetchAsString &&
|
|
9
|
+
options.fetchAsString.includes(DataTypeOIDs.jsonb);
|
|
9
10
|
if (fetchAsString)
|
|
10
11
|
return content;
|
|
11
12
|
return content ? JSON.parse(content) : undefined;
|
|
@@ -18,7 +19,8 @@ export const JsonType = {
|
|
|
18
19
|
return '' + v;
|
|
19
20
|
},
|
|
20
21
|
parseText(v, options) {
|
|
21
|
-
const fetchAsString = options.fetchAsString &&
|
|
22
|
+
const fetchAsString = options.fetchAsString &&
|
|
23
|
+
options.fetchAsString.includes(DataTypeOIDs.jsonb);
|
|
22
24
|
if (fetchAsString)
|
|
23
25
|
return v;
|
|
24
26
|
return v ? JSON.parse(v) : null;
|
|
@@ -8,7 +8,8 @@ export const JsonbType = {
|
|
|
8
8
|
const buf = new BufferReader(v);
|
|
9
9
|
if (buf.readUInt8() !== 1)
|
|
10
10
|
throw new Error('Unexpected Jsonb version value in header');
|
|
11
|
-
const fetchAsString = options.fetchAsString &&
|
|
11
|
+
const fetchAsString = options.fetchAsString &&
|
|
12
|
+
options.fetchAsString.includes(DataTypeOIDs.json);
|
|
12
13
|
const content = buf.readLString(buf.length - buf.offset);
|
|
13
14
|
if (fetchAsString)
|
|
14
15
|
return content;
|
|
@@ -22,7 +23,8 @@ export const JsonbType = {
|
|
|
22
23
|
return '\x0001' + v;
|
|
23
24
|
},
|
|
24
25
|
parseText(v, options) {
|
|
25
|
-
const fetchAsString = options.fetchAsString &&
|
|
26
|
+
const fetchAsString = options.fetchAsString &&
|
|
27
|
+
options.fetchAsString.includes(DataTypeOIDs.json);
|
|
26
28
|
if (fetchAsString)
|
|
27
29
|
return v;
|
|
28
30
|
return v ? JSON.parse(v) : null;
|
|
@@ -22,7 +22,10 @@ export const LsegType = {
|
|
|
22
22
|
buf.writeDoubleBE(v.y2);
|
|
23
23
|
},
|
|
24
24
|
parseText(v) {
|
|
25
|
-
const m = v.match(LSEG_PATTERN1) ||
|
|
25
|
+
const m = v.match(LSEG_PATTERN1) ||
|
|
26
|
+
v.match(LSEG_PATTERN2) ||
|
|
27
|
+
v.match(LSEG_PATTERN3) ||
|
|
28
|
+
v.match(LSEG_PATTERN4);
|
|
26
29
|
if (!m)
|
|
27
30
|
return undefined;
|
|
28
31
|
return {
|
|
@@ -25,7 +25,10 @@ export const PointType = {
|
|
|
25
25
|
};
|
|
26
26
|
},
|
|
27
27
|
isType(v) {
|
|
28
|
-
return typeof v === 'object' &&
|
|
28
|
+
return (typeof v === 'object' &&
|
|
29
|
+
Object.keys(v).length === 2 &&
|
|
30
|
+
typeof v.x === 'number' &&
|
|
31
|
+
typeof v.y === 'number');
|
|
29
32
|
},
|
|
30
33
|
};
|
|
31
34
|
export const ArrayPointType = {
|