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
|
@@ -12,7 +12,9 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
12
12
|
super();
|
|
13
13
|
this._notificationListeners = new safe_event_emitter_js_1.SafeEventEmitter();
|
|
14
14
|
this._closing = false;
|
|
15
|
-
if (arg0 &&
|
|
15
|
+
if (arg0 &&
|
|
16
|
+
typeof arg0 === 'object' &&
|
|
17
|
+
typeof arg0.acquire === 'function') {
|
|
16
18
|
if (!(arg1 instanceof intl_connection_js_1.IntlConnection))
|
|
17
19
|
throw new TypeError('Invalid argument');
|
|
18
20
|
this._pool = arg0;
|
|
@@ -94,7 +96,9 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
98
|
this._closing = true;
|
|
97
|
-
if (this._intlCon.refCount > 0 &&
|
|
99
|
+
if (this._intlCon.refCount > 0 &&
|
|
100
|
+
typeof terminateWait === 'number' &&
|
|
101
|
+
terminateWait > 0) {
|
|
98
102
|
const startTime = Date.now();
|
|
99
103
|
return this._captureErrorStack(new Promise((resolve, reject) => {
|
|
100
104
|
/* istanbul ignore next */
|
|
@@ -106,7 +110,8 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
const timer = setInterval(() => {
|
|
109
|
-
if (this._intlCon.refCount <= 0 ||
|
|
113
|
+
if (this._intlCon.refCount <= 0 ||
|
|
114
|
+
Date.now() > startTime + terminateWait) {
|
|
110
115
|
clearInterval(timer);
|
|
111
116
|
if (this._intlCon.refCount > 0) {
|
|
112
117
|
/* istanbul ignore next */
|
|
@@ -156,7 +161,7 @@ class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
156
161
|
throw this._handleError(e, sql);
|
|
157
162
|
});
|
|
158
163
|
try {
|
|
159
|
-
const params = options?.params?.map(prm =>
|
|
164
|
+
const params = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.value : prm);
|
|
160
165
|
return await this._captureErrorStack(statement.execute({ ...options, params }));
|
|
161
166
|
}
|
|
162
167
|
finally {
|
|
@@ -65,9 +65,11 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
65
65
|
});
|
|
66
66
|
let startupCommand = '';
|
|
67
67
|
if (this.config.schema)
|
|
68
|
-
startupCommand +=
|
|
68
|
+
startupCommand +=
|
|
69
|
+
'SET search_path = ' + (0, escape_literal_js_1.escapeLiteral)(this.config.schema) + ';';
|
|
69
70
|
if (this.config.timezone)
|
|
70
|
-
startupCommand +=
|
|
71
|
+
startupCommand +=
|
|
72
|
+
'SET timezone TO ' + (0, escape_literal_js_1.escapeLiteral)(this.config.timezone) + ';';
|
|
71
73
|
if (startupCommand)
|
|
72
74
|
await this.execute(startupCommand, { autoCommit: true });
|
|
73
75
|
this.emit('ready');
|
|
@@ -95,7 +97,9 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
95
97
|
let commitLast = false;
|
|
96
98
|
if (!transactionCommand) {
|
|
97
99
|
if (!this.inTransaction &&
|
|
98
|
-
(options?.autoCommit != null
|
|
100
|
+
(options?.autoCommit != null
|
|
101
|
+
? options?.autoCommit
|
|
102
|
+
: this.config.autoCommit) === false) {
|
|
99
103
|
beginFirst = true;
|
|
100
104
|
}
|
|
101
105
|
if (this.inTransaction && options?.autoCommit)
|
|
@@ -211,12 +215,15 @@ class IntlConnection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
211
215
|
case protocol_js_1.Protocol.BackendMessageCode.CommandComplete:
|
|
212
216
|
// Ignore BEGIN command that we added to sql
|
|
213
217
|
current.command = msg.command;
|
|
214
|
-
if (current.command === 'DELETE' ||
|
|
218
|
+
if (current.command === 'DELETE' ||
|
|
219
|
+
current.command === 'INSERT' ||
|
|
220
|
+
current.command === 'UPDATE') {
|
|
215
221
|
current.rowsAffected = msg.rowCount;
|
|
216
222
|
}
|
|
217
223
|
current.executeTime = Date.now() - currentStart;
|
|
218
224
|
if (current.rows)
|
|
219
|
-
current.rowType =
|
|
225
|
+
current.rowType =
|
|
226
|
+
opts.objectRows && current.fields ? 'object' : 'array';
|
|
220
227
|
result.results.push(current);
|
|
221
228
|
if (cb)
|
|
222
229
|
cb('command-complete', current);
|
package/cjs/connection/portal.js
CHANGED
|
@@ -22,7 +22,10 @@ class Portal {
|
|
|
22
22
|
intoCon.ref();
|
|
23
23
|
try {
|
|
24
24
|
const socket = intoCon.socket;
|
|
25
|
-
this._columnFormat =
|
|
25
|
+
this._columnFormat =
|
|
26
|
+
queryOptions.columnFormat != null
|
|
27
|
+
? queryOptions.columnFormat
|
|
28
|
+
: protocol_js_1.Protocol.DataFormat.binary;
|
|
26
29
|
socket.sendBindMessage({
|
|
27
30
|
typeMap: queryOptions.typeMap || data_type_map_js_1.GlobalTypeMap,
|
|
28
31
|
statement: this._statement.name,
|
|
@@ -79,7 +82,10 @@ class Portal {
|
|
|
79
82
|
intoCon.ref();
|
|
80
83
|
try {
|
|
81
84
|
const socket = intoCon.socket;
|
|
82
|
-
socket.sendExecuteMessage({
|
|
85
|
+
socket.sendExecuteMessage({
|
|
86
|
+
portal: this.name,
|
|
87
|
+
fetchCount: fetchCount || 100,
|
|
88
|
+
});
|
|
83
89
|
socket.sendFlushMessage();
|
|
84
90
|
const rows = [];
|
|
85
91
|
return await socket.capture(async (code, msg, done) => {
|
|
@@ -91,7 +97,8 @@ class Portal {
|
|
|
91
97
|
break;
|
|
92
98
|
case protocol_js_1.Protocol.BackendMessageCode.DataRow:
|
|
93
99
|
if (Array.isArray(this._columnFormat)) {
|
|
94
|
-
rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
|
|
100
|
+
rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
|
|
101
|
+
protocol_js_1.Protocol.DataFormat.text
|
|
95
102
|
? buf.toString('utf8')
|
|
96
103
|
: buf));
|
|
97
104
|
}
|
|
@@ -85,7 +85,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
85
85
|
let commitLast = false;
|
|
86
86
|
if (!transactionCommand) {
|
|
87
87
|
if (!intlCon.inTransaction &&
|
|
88
|
-
(options?.autoCommit != null
|
|
88
|
+
(options?.autoCommit != null
|
|
89
|
+
? options?.autoCommit
|
|
90
|
+
: intlCon.config.autoCommit) === false) {
|
|
89
91
|
beginFirst = true;
|
|
90
92
|
}
|
|
91
93
|
if (intlCon.inTransaction && options?.autoCommit)
|
|
@@ -100,7 +102,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
100
102
|
if (intlCon.inTransaction && rollbackOnError)
|
|
101
103
|
await intlCon.execute('SAVEPOINT ' + this._onErrorSavePoint);
|
|
102
104
|
try {
|
|
103
|
-
const result = await intlCon.statementQueue
|
|
105
|
+
const result = await intlCon.statementQueue
|
|
106
|
+
.enqueue(() => this._execute(options))
|
|
107
|
+
.toPromise();
|
|
104
108
|
if (commitLast)
|
|
105
109
|
await intlCon.execute('COMMIT');
|
|
106
110
|
else if (intlCon.inTransaction && rollbackOnError) {
|
|
@@ -171,7 +175,9 @@ class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
|
-
if (result.command === 'DELETE' ||
|
|
178
|
+
if (result.command === 'DELETE' ||
|
|
179
|
+
result.command === 'INSERT' ||
|
|
180
|
+
result.command === 'UPDATE') {
|
|
175
181
|
result.rowsAffected = executeResult.rowCount;
|
|
176
182
|
}
|
|
177
183
|
result.executeTime = Date.now() - startTime;
|
package/cjs/constants.js
CHANGED
package/cjs/data-type-map.js
CHANGED
|
@@ -82,21 +82,33 @@ exports.GlobalTypeMap.register([point_type_js_1.PointType, point_type_js_1.Array
|
|
|
82
82
|
exports.GlobalTypeMap.register([lseg_type_js_1.LsegType, lseg_type_js_1.ArrayLsegType]);
|
|
83
83
|
exports.GlobalTypeMap.register([box_type_js_1.BoxType, box_type_js_1.ArrayBoxType]);
|
|
84
84
|
exports.GlobalTypeMap.register([int2_vector_type_js_1.Int2VectorType, int2_vector_type_js_1.ArrayInt2VectorType]);
|
|
85
|
-
exports.GlobalTypeMap.register({
|
|
85
|
+
exports.GlobalTypeMap.register({
|
|
86
|
+
...varchar_type_js_1.VarcharType,
|
|
87
|
+
name: 'bpchar',
|
|
88
|
+
oid: constants_js_1.DataTypeOIDs.bpchar,
|
|
89
|
+
});
|
|
86
90
|
exports.GlobalTypeMap.register({
|
|
87
91
|
...varchar_type_js_1.ArrayVarcharType,
|
|
88
92
|
name: '_bpchar',
|
|
89
93
|
oid: constants_js_1.DataTypeOIDs._bpchar,
|
|
90
94
|
elementsOID: constants_js_1.DataTypeOIDs.bpchar,
|
|
91
95
|
});
|
|
92
|
-
exports.GlobalTypeMap.register({
|
|
96
|
+
exports.GlobalTypeMap.register({
|
|
97
|
+
...varchar_type_js_1.VarcharType,
|
|
98
|
+
name: 'name',
|
|
99
|
+
oid: constants_js_1.DataTypeOIDs.name,
|
|
100
|
+
});
|
|
93
101
|
exports.GlobalTypeMap.register({
|
|
94
102
|
...varchar_type_js_1.ArrayVarcharType,
|
|
95
103
|
name: '_name',
|
|
96
104
|
oid: constants_js_1.DataTypeOIDs._name,
|
|
97
105
|
elementsOID: constants_js_1.DataTypeOIDs.name,
|
|
98
106
|
});
|
|
99
|
-
exports.GlobalTypeMap.register({
|
|
107
|
+
exports.GlobalTypeMap.register({
|
|
108
|
+
...varchar_type_js_1.VarcharType,
|
|
109
|
+
name: 'text',
|
|
110
|
+
oid: constants_js_1.DataTypeOIDs.text,
|
|
111
|
+
});
|
|
100
112
|
exports.GlobalTypeMap.register({
|
|
101
113
|
...varchar_type_js_1.ArrayVarcharType,
|
|
102
114
|
name: '_text',
|
|
@@ -13,7 +13,13 @@ exports.BoolType = {
|
|
|
13
13
|
buf.writeInt8(v ? 1 : 0);
|
|
14
14
|
},
|
|
15
15
|
parseText(v) {
|
|
16
|
-
return v === 'TRUE' ||
|
|
16
|
+
return (v === 'TRUE' ||
|
|
17
|
+
v === 't' ||
|
|
18
|
+
v === 'true' ||
|
|
19
|
+
v === 'y' ||
|
|
20
|
+
v === 'yes' ||
|
|
21
|
+
v === 'on' ||
|
|
22
|
+
v === '1');
|
|
17
23
|
},
|
|
18
24
|
isType(v) {
|
|
19
25
|
return typeof v === 'boolean';
|
|
@@ -23,7 +23,10 @@ exports.CircleType = {
|
|
|
23
23
|
buf.writeDoubleBE(v.r);
|
|
24
24
|
},
|
|
25
25
|
parseText(v) {
|
|
26
|
-
const m = v.match(CIRCLE_PATTERN1) ||
|
|
26
|
+
const m = v.match(CIRCLE_PATTERN1) ||
|
|
27
|
+
v.match(CIRCLE_PATTERN2) ||
|
|
28
|
+
v.match(CIRCLE_PATTERN3) ||
|
|
29
|
+
v.match(CIRCLE_PATTERN4);
|
|
27
30
|
if (!m)
|
|
28
31
|
return undefined;
|
|
29
32
|
return {
|
|
@@ -9,7 +9,8 @@ exports.DateType = {
|
|
|
9
9
|
oid: constants_js_1.DataTypeOIDs.date,
|
|
10
10
|
jsType: 'Date',
|
|
11
11
|
parseBinary(v, options) {
|
|
12
|
-
const fetchAsString = options.fetchAsString &&
|
|
12
|
+
const fetchAsString = options.fetchAsString &&
|
|
13
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.date);
|
|
13
14
|
const t = v.readInt32BE();
|
|
14
15
|
if (t === 0x7fffffff)
|
|
15
16
|
return fetchAsString ? 'infinity' : Infinity;
|
|
@@ -34,13 +35,16 @@ exports.DateType = {
|
|
|
34
35
|
}
|
|
35
36
|
if (!(v instanceof Date))
|
|
36
37
|
v = new Date(v);
|
|
37
|
-
let n = options.utcDates
|
|
38
|
+
let n = options.utcDates
|
|
39
|
+
? v.getTime()
|
|
40
|
+
: v.getTime() - v.getTimezoneOffset() * 60 * 1000;
|
|
38
41
|
n = (n - timeShift) / 1000 / 86400;
|
|
39
42
|
const t = Math.trunc(n + Number.EPSILON);
|
|
40
43
|
buf.writeInt32BE(t);
|
|
41
44
|
},
|
|
42
45
|
parseText(v, options) {
|
|
43
|
-
const fetchAsString = options.fetchAsString &&
|
|
46
|
+
const fetchAsString = options.fetchAsString &&
|
|
47
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.date);
|
|
44
48
|
if (fetchAsString)
|
|
45
49
|
return v;
|
|
46
50
|
return (0, parse_datetime_js_1.parseDateTime)(v, false, false, options.utcDates);
|
|
@@ -57,7 +61,11 @@ function padZero(v) {
|
|
|
57
61
|
return v < 9 ? '0' + v : '' + v;
|
|
58
62
|
}
|
|
59
63
|
function dateToDateString(d) {
|
|
60
|
-
return d.getFullYear() +
|
|
64
|
+
return (d.getFullYear() +
|
|
65
|
+
'-' +
|
|
66
|
+
padZero(d.getMonth() + 1) +
|
|
67
|
+
'-' +
|
|
68
|
+
padZero(d.getDate()));
|
|
61
69
|
}
|
|
62
70
|
exports.ArrayDateType = {
|
|
63
71
|
...exports.DateType,
|
|
@@ -15,7 +15,7 @@ exports.Int2Type = {
|
|
|
15
15
|
},
|
|
16
16
|
parseText: fast_parseint_js_1.fastParseInt,
|
|
17
17
|
isType(v) {
|
|
18
|
-
return typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767;
|
|
18
|
+
return (typeof v === 'number' && Number.isInteger(v) && v >= -32768 && v <= 32767);
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
21
|
exports.ArrayInt2Type = {
|
|
@@ -27,7 +27,11 @@ exports.Int2VectorType = {
|
|
|
27
27
|
return v.join(' ');
|
|
28
28
|
},
|
|
29
29
|
isType(v) {
|
|
30
|
-
return (Array.isArray(v) &&
|
|
30
|
+
return (Array.isArray(v) &&
|
|
31
|
+
!v.find(x => !(typeof x === 'number' &&
|
|
32
|
+
Number.isInteger(x) &&
|
|
33
|
+
x >= -32768 &&
|
|
34
|
+
x <= 32767)));
|
|
31
35
|
},
|
|
32
36
|
};
|
|
33
37
|
exports.ArrayInt2VectorType = {
|
|
@@ -15,7 +15,9 @@ exports.Int4Type = {
|
|
|
15
15
|
},
|
|
16
16
|
parseText: fast_parseint_js_1.fastParseInt,
|
|
17
17
|
isType(v) {
|
|
18
|
-
return typeof v === 'number' &&
|
|
18
|
+
return (typeof v === 'number' &&
|
|
19
|
+
Number.isInteger(v) &&
|
|
20
|
+
v <= Number.MAX_SAFE_INTEGER);
|
|
19
21
|
},
|
|
20
22
|
};
|
|
21
23
|
exports.ArrayInt4Type = {
|
|
@@ -9,7 +9,9 @@ exports.Int8Type = {
|
|
|
9
9
|
oid: constants_js_1.DataTypeOIDs.int8,
|
|
10
10
|
jsType: 'BigInt',
|
|
11
11
|
parseBinary(buf) {
|
|
12
|
-
const v = typeof buf.readBigInt64BE === 'function'
|
|
12
|
+
const v = typeof buf.readBigInt64BE === 'function'
|
|
13
|
+
? buf.readBigInt64BE(0)
|
|
14
|
+
: (0, bigint_methods_js_1.readBigInt64BE)(buf);
|
|
13
15
|
return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
|
|
14
16
|
},
|
|
15
17
|
encodeBinary(buf, v) {
|
|
@@ -20,7 +22,10 @@ exports.Int8Type = {
|
|
|
20
22
|
return v >= -maxSafeInteger && v <= maxSafeInteger ? Number(v) : v;
|
|
21
23
|
},
|
|
22
24
|
isType(v) {
|
|
23
|
-
return typeof v === 'bigint' ||
|
|
25
|
+
return (typeof v === 'bigint' ||
|
|
26
|
+
(typeof v === 'number' &&
|
|
27
|
+
Number.isInteger(v) &&
|
|
28
|
+
v > Number.MAX_SAFE_INTEGER));
|
|
24
29
|
},
|
|
25
30
|
};
|
|
26
31
|
exports.ArrayInt8Type = {
|
|
@@ -8,7 +8,8 @@ exports.JsonType = {
|
|
|
8
8
|
jsType: 'string',
|
|
9
9
|
parseBinary(v, options) {
|
|
10
10
|
const content = v.toString('utf8');
|
|
11
|
-
const fetchAsString = options.fetchAsString &&
|
|
11
|
+
const fetchAsString = options.fetchAsString &&
|
|
12
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
|
|
12
13
|
if (fetchAsString)
|
|
13
14
|
return content;
|
|
14
15
|
return content ? JSON.parse(content) : undefined;
|
|
@@ -21,7 +22,8 @@ exports.JsonType = {
|
|
|
21
22
|
return '' + v;
|
|
22
23
|
},
|
|
23
24
|
parseText(v, options) {
|
|
24
|
-
const fetchAsString = options.fetchAsString &&
|
|
25
|
+
const fetchAsString = options.fetchAsString &&
|
|
26
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.jsonb);
|
|
25
27
|
if (fetchAsString)
|
|
26
28
|
return v;
|
|
27
29
|
return v ? JSON.parse(v) : null;
|
|
@@ -11,7 +11,8 @@ exports.JsonbType = {
|
|
|
11
11
|
const buf = new buffer_reader_js_1.BufferReader(v);
|
|
12
12
|
if (buf.readUInt8() !== 1)
|
|
13
13
|
throw new Error('Unexpected Jsonb version value in header');
|
|
14
|
-
const fetchAsString = options.fetchAsString &&
|
|
14
|
+
const fetchAsString = options.fetchAsString &&
|
|
15
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
|
|
15
16
|
const content = buf.readLString(buf.length - buf.offset);
|
|
16
17
|
if (fetchAsString)
|
|
17
18
|
return content;
|
|
@@ -25,7 +26,8 @@ exports.JsonbType = {
|
|
|
25
26
|
return '\x0001' + v;
|
|
26
27
|
},
|
|
27
28
|
parseText(v, options) {
|
|
28
|
-
const fetchAsString = options.fetchAsString &&
|
|
29
|
+
const fetchAsString = options.fetchAsString &&
|
|
30
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.json);
|
|
29
31
|
if (fetchAsString)
|
|
30
32
|
return v;
|
|
31
33
|
return v ? JSON.parse(v) : null;
|
|
@@ -25,7 +25,10 @@ exports.LsegType = {
|
|
|
25
25
|
buf.writeDoubleBE(v.y2);
|
|
26
26
|
},
|
|
27
27
|
parseText(v) {
|
|
28
|
-
const m = v.match(LSEG_PATTERN1) ||
|
|
28
|
+
const m = v.match(LSEG_PATTERN1) ||
|
|
29
|
+
v.match(LSEG_PATTERN2) ||
|
|
30
|
+
v.match(LSEG_PATTERN3) ||
|
|
31
|
+
v.match(LSEG_PATTERN4);
|
|
29
32
|
if (!m)
|
|
30
33
|
return undefined;
|
|
31
34
|
return {
|
|
@@ -28,7 +28,10 @@ exports.PointType = {
|
|
|
28
28
|
};
|
|
29
29
|
},
|
|
30
30
|
isType(v) {
|
|
31
|
-
return typeof v === 'object' &&
|
|
31
|
+
return (typeof v === 'object' &&
|
|
32
|
+
Object.keys(v).length === 2 &&
|
|
33
|
+
typeof v.x === 'number' &&
|
|
34
|
+
typeof v.y === 'number');
|
|
32
35
|
},
|
|
33
36
|
};
|
|
34
37
|
exports.ArrayPointType = {
|
|
@@ -9,7 +9,8 @@ exports.TimeType = {
|
|
|
9
9
|
oid: constants_js_1.DataTypeOIDs.time,
|
|
10
10
|
jsType: 'string',
|
|
11
11
|
parseBinary(v, options) {
|
|
12
|
-
const fetchAsString = options.fetchAsString &&
|
|
12
|
+
const fetchAsString = options.fetchAsString &&
|
|
13
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time);
|
|
13
14
|
const hi = v.readInt32BE();
|
|
14
15
|
const lo = v.readUInt32BE(4);
|
|
15
16
|
let d = new Date((lo + hi * timeMul) / 1000);
|
|
@@ -24,7 +25,9 @@ exports.TimeType = {
|
|
|
24
25
|
if (!(v instanceof Date))
|
|
25
26
|
v = new Date(v);
|
|
26
27
|
// Postgresql ignores timezone data so we are
|
|
27
|
-
let n = options.utcDates
|
|
28
|
+
let n = options.utcDates
|
|
29
|
+
? v.getTime()
|
|
30
|
+
: v.getTime() - v.getTimezoneOffset() * 60 * 1000;
|
|
28
31
|
n = n * 1000;
|
|
29
32
|
const hi = Math.floor(n / timeMul);
|
|
30
33
|
const lo = n - hi * timeMul;
|
|
@@ -32,12 +35,16 @@ exports.TimeType = {
|
|
|
32
35
|
buf.writeUInt32BE(lo);
|
|
33
36
|
},
|
|
34
37
|
parseText(v, options) {
|
|
35
|
-
if (options.fetchAsString &&
|
|
38
|
+
if (options.fetchAsString &&
|
|
39
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.time))
|
|
36
40
|
return v;
|
|
37
41
|
return (0, parse_time_js_1.parseTime)(v, false, options.utcDates);
|
|
38
42
|
},
|
|
39
43
|
isType(v) {
|
|
40
|
-
return ((v instanceof Date &&
|
|
44
|
+
return ((v instanceof Date &&
|
|
45
|
+
v.getFullYear() === 1970 &&
|
|
46
|
+
v.getMonth() === 0 &&
|
|
47
|
+
v.getDate() === 1) ||
|
|
41
48
|
(typeof v === 'string' && parse_time_js_1.STRICT_TIME_PATTERN.test(v)));
|
|
42
49
|
},
|
|
43
50
|
};
|
|
@@ -45,7 +52,11 @@ function padZero(v) {
|
|
|
45
52
|
return v < 9 ? '0' + v : '' + v;
|
|
46
53
|
}
|
|
47
54
|
function dateToTimeString(d) {
|
|
48
|
-
return padZero(d.getHours()) +
|
|
55
|
+
return (padZero(d.getHours()) +
|
|
56
|
+
':' +
|
|
57
|
+
padZero(d.getMinutes()) +
|
|
58
|
+
':' +
|
|
59
|
+
padZero(d.getSeconds()));
|
|
49
60
|
}
|
|
50
61
|
exports.ArrayTimeType = {
|
|
51
62
|
...exports.TimeType,
|
|
@@ -10,7 +10,8 @@ exports.TimestampType = {
|
|
|
10
10
|
oid: constants_js_1.DataTypeOIDs.timestamp,
|
|
11
11
|
jsType: 'Date',
|
|
12
12
|
parseBinary(v, options) {
|
|
13
|
-
const fetchAsString = options.fetchAsString &&
|
|
13
|
+
const fetchAsString = options.fetchAsString &&
|
|
14
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp);
|
|
14
15
|
const hi = v.readInt32BE();
|
|
15
16
|
const lo = v.readUInt32BE(4);
|
|
16
17
|
if (lo === 0xffffffff && hi === 0x7fffffff)
|
|
@@ -40,7 +41,9 @@ exports.TimestampType = {
|
|
|
40
41
|
if (!(v instanceof Date))
|
|
41
42
|
v = new Date(v);
|
|
42
43
|
// Postgresql ignores timezone data so we are
|
|
43
|
-
let n = options.utcDates
|
|
44
|
+
let n = options.utcDates
|
|
45
|
+
? v.getTime()
|
|
46
|
+
: v.getTime() - v.getTimezoneOffset() * 60 * 1000;
|
|
44
47
|
n = (n - timeShift) * 1000;
|
|
45
48
|
const hi = Math.floor(n / timeMul);
|
|
46
49
|
const lo = n - hi * timeMul;
|
|
@@ -48,14 +51,18 @@ exports.TimestampType = {
|
|
|
48
51
|
buf.writeUInt32BE(lo);
|
|
49
52
|
},
|
|
50
53
|
parseText(v, options) {
|
|
51
|
-
if (options.fetchAsString &&
|
|
54
|
+
if (options.fetchAsString &&
|
|
55
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamp))
|
|
52
56
|
return v;
|
|
53
57
|
return (0, parse_datetime_js_1.parseDateTime)(v, true, false, options.utcDates);
|
|
54
58
|
},
|
|
55
59
|
isType(v) {
|
|
56
60
|
return (v instanceof Date &&
|
|
57
61
|
!(v.getFullYear() === 1970 && v.getMonth() === 0 && v.getDate() === 1) &&
|
|
58
|
-
!(v.getHours() === 0 &&
|
|
62
|
+
!(v.getHours() === 0 &&
|
|
63
|
+
v.getMinutes() === 0 &&
|
|
64
|
+
v.getSeconds() === 0 &&
|
|
65
|
+
v.getMilliseconds() === 0));
|
|
59
66
|
},
|
|
60
67
|
};
|
|
61
68
|
function padZero(v) {
|
|
@@ -10,7 +10,8 @@ exports.TimestamptzType = {
|
|
|
10
10
|
oid: constants_js_1.DataTypeOIDs.timestamptz,
|
|
11
11
|
jsType: 'Date',
|
|
12
12
|
parseBinary(v, options) {
|
|
13
|
-
const fetchAsString = options.fetchAsString &&
|
|
13
|
+
const fetchAsString = options.fetchAsString &&
|
|
14
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamptz);
|
|
14
15
|
const hi = v.readInt32BE();
|
|
15
16
|
const lo = v.readUInt32BE(4);
|
|
16
17
|
if (lo === 0xffffffff && hi === 0x7fffffff)
|
|
@@ -48,7 +49,8 @@ exports.TimestamptzType = {
|
|
|
48
49
|
},
|
|
49
50
|
parseText(v, options) {
|
|
50
51
|
const d = (0, parse_datetime_js_1.parseDateTime)(v, true, true, options.utcDates);
|
|
51
|
-
if (options.fetchAsString &&
|
|
52
|
+
if (options.fetchAsString &&
|
|
53
|
+
options.fetchAsString.includes(constants_js_1.DataTypeOIDs.timestamptz)) {
|
|
52
54
|
if (d instanceof Date)
|
|
53
55
|
return dateToTimestamptzString(d);
|
|
54
56
|
if (d === Infinity)
|
package/cjs/protocol/backend.js
CHANGED
|
@@ -154,13 +154,17 @@ function parseCopyData(io, code, len) {
|
|
|
154
154
|
}
|
|
155
155
|
function parseCopyResponse(io) {
|
|
156
156
|
const out = {
|
|
157
|
-
overallFormat: io.readUInt8() === 0
|
|
157
|
+
overallFormat: io.readUInt8() === 0
|
|
158
|
+
? protocol_js_1.Protocol.DataFormat.text
|
|
159
|
+
: protocol_js_1.Protocol.DataFormat.binary,
|
|
158
160
|
columnCount: io.readUInt16BE(),
|
|
159
161
|
};
|
|
160
162
|
if (out.columnCount) {
|
|
161
163
|
out.columnFormats = [];
|
|
162
164
|
for (let i = 0; i < out.columnCount; i++) {
|
|
163
|
-
out.columnFormats.push(io.readUInt16BE() === 0
|
|
165
|
+
out.columnFormats.push(io.readUInt16BE() === 0
|
|
166
|
+
? protocol_js_1.Protocol.DataFormat.text
|
|
167
|
+
: protocol_js_1.Protocol.DataFormat.binary);
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
return out;
|
|
@@ -248,7 +252,9 @@ function parseRowDescription(io) {
|
|
|
248
252
|
dataTypeId: io.readInt32BE(),
|
|
249
253
|
fixedSize: io.readInt16BE(),
|
|
250
254
|
modifier: io.readInt32BE(),
|
|
251
|
-
format: io.readInt16BE() === 0
|
|
255
|
+
format: io.readInt16BE() === 0
|
|
256
|
+
? protocol_js_1.Protocol.DataFormat.text
|
|
257
|
+
: protocol_js_1.Protocol.DataFormat.binary,
|
|
252
258
|
};
|
|
253
259
|
out.fields.push(field);
|
|
254
260
|
}
|
package/cjs/protocol/frontend.js
CHANGED
|
@@ -7,9 +7,27 @@ const stringify_arrayliteral_js_1 = require("../util/stringify-arrayliteral.js")
|
|
|
7
7
|
const protocol_js_1 = require("./protocol.js");
|
|
8
8
|
const smart_buffer_js_1 = require("./smart-buffer.js");
|
|
9
9
|
const DataFormat = protocol_js_1.Protocol.DataFormat;
|
|
10
|
-
const StaticFlushBuffer = Buffer.from([
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const StaticFlushBuffer = Buffer.from([
|
|
11
|
+
protocol_js_1.Protocol.FrontendMessageCode.Flush,
|
|
12
|
+
0x00,
|
|
13
|
+
0x00,
|
|
14
|
+
0x00,
|
|
15
|
+
0x04,
|
|
16
|
+
]);
|
|
17
|
+
const StaticTerminateBuffer = Buffer.from([
|
|
18
|
+
protocol_js_1.Protocol.FrontendMessageCode.Terminate,
|
|
19
|
+
0x00,
|
|
20
|
+
0x00,
|
|
21
|
+
0x00,
|
|
22
|
+
0x04,
|
|
23
|
+
]);
|
|
24
|
+
const StaticSyncBuffer = Buffer.from([
|
|
25
|
+
protocol_js_1.Protocol.FrontendMessageCode.Sync,
|
|
26
|
+
0x00,
|
|
27
|
+
0x00,
|
|
28
|
+
0x00,
|
|
29
|
+
0x04,
|
|
30
|
+
]);
|
|
13
31
|
class Frontend {
|
|
14
32
|
constructor(options) {
|
|
15
33
|
this._io = new smart_buffer_js_1.SmartBuffer(options?.buffer);
|
|
@@ -32,7 +50,9 @@ class Frontend {
|
|
|
32
50
|
if (k !== 'client_encoding')
|
|
33
51
|
io.writeCString(k, 'utf8').writeCString(v, 'utf8');
|
|
34
52
|
}
|
|
35
|
-
io.writeCString('client_encoding', 'utf8')
|
|
53
|
+
io.writeCString('client_encoding', 'utf8')
|
|
54
|
+
.writeCString('UTF8', 'utf8')
|
|
55
|
+
.writeUInt8(0);
|
|
36
56
|
return setLengthAndFlush(io, 0);
|
|
37
57
|
}
|
|
38
58
|
getPasswordMessage(password) {
|
|
@@ -89,7 +109,9 @@ class Frontend {
|
|
|
89
109
|
.writeCString(args.portal || '', 'utf8')
|
|
90
110
|
.writeCString(args.statement || '', 'utf8');
|
|
91
111
|
const { params, paramTypes, queryOptions } = args;
|
|
92
|
-
const columnFormat = queryOptions.columnFormat != null
|
|
112
|
+
const columnFormat = queryOptions.columnFormat != null
|
|
113
|
+
? queryOptions.columnFormat
|
|
114
|
+
: constants_js_1.DEFAULT_COLUMN_FORMAT;
|
|
93
115
|
if (params && params.length) {
|
|
94
116
|
io.writeInt16BE(params.length);
|
|
95
117
|
const formatOffset = io.offset;
|
|
@@ -107,7 +129,8 @@ class Frontend {
|
|
|
107
129
|
const dataTypeOid = paramTypes ? paramTypes[i] : undefined;
|
|
108
130
|
const dt = dataTypeOid ? args.typeMap.get(dataTypeOid) : undefined;
|
|
109
131
|
if (dt) {
|
|
110
|
-
if (typeof dt.encodeAsNull === 'function' &&
|
|
132
|
+
if (typeof dt.encodeAsNull === 'function' &&
|
|
133
|
+
dt.encodeAsNull(v, queryOptions)) {
|
|
111
134
|
io.writeInt32BE(-1);
|
|
112
135
|
continue;
|
|
113
136
|
}
|
|
@@ -128,7 +151,9 @@ class Frontend {
|
|
|
128
151
|
io.buffer.writeInt32BE(io.length - dataOffset, dataOffset - 4); // Update length
|
|
129
152
|
}
|
|
130
153
|
else if (typeof dt.encodeText === 'function') {
|
|
131
|
-
v = dt.elementsOID
|
|
154
|
+
v = dt.elementsOID
|
|
155
|
+
? (0, stringify_arrayliteral_js_1.stringifyArrayLiteral)(v, queryOptions, dt.encodeText)
|
|
156
|
+
: dt.encodeText(v, queryOptions);
|
|
132
157
|
io.writeLString(v, 'utf8');
|
|
133
158
|
}
|
|
134
159
|
}
|
|
@@ -166,7 +191,9 @@ class Frontend {
|
|
|
166
191
|
}
|
|
167
192
|
getDescribeMessage(args) {
|
|
168
193
|
if (args.name && args.name.length > 63) {
|
|
169
|
-
throw new Error(args.type === 'P'
|
|
194
|
+
throw new Error(args.type === 'P'
|
|
195
|
+
? 'Portal'
|
|
196
|
+
: 'Statement name length must be lower than 63');
|
|
170
197
|
}
|
|
171
198
|
const io = this._io
|
|
172
199
|
.start()
|
|
@@ -177,7 +204,8 @@ class Frontend {
|
|
|
177
204
|
return setLengthAndFlush(io, 1);
|
|
178
205
|
}
|
|
179
206
|
getExecuteMessage(args) {
|
|
180
|
-
if (args.fetchCount &&
|
|
207
|
+
if (args.fetchCount &&
|
|
208
|
+
(args.fetchCount < 0 || args.fetchCount > 4294967295)) {
|
|
181
209
|
throw new Error('fetchCount can be between 0 and 4294967295');
|
|
182
210
|
}
|
|
183
211
|
const io = this._io
|
|
@@ -190,7 +218,9 @@ class Frontend {
|
|
|
190
218
|
}
|
|
191
219
|
getCloseMessage(args) {
|
|
192
220
|
if (args.name && args.name.length > 63) {
|
|
193
|
-
throw new Error(args.type === 'P'
|
|
221
|
+
throw new Error(args.type === 'P'
|
|
222
|
+
? 'Portal'
|
|
223
|
+
: 'Statement name length must be lower than 63');
|
|
194
224
|
}
|
|
195
225
|
const io = this._io
|
|
196
226
|
.start()
|