postgrejs 2.12.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.
- package/CHANGELOG.md +814 -0
- package/LICENSE +21 -0
- package/README.md +200 -0
- package/cjs/connection/bind-param.js +10 -0
- package/cjs/connection/connection.js +279 -0
- package/cjs/connection/cursor.js +93 -0
- package/cjs/connection/intl-connection.js +243 -0
- package/cjs/connection/pool.js +226 -0
- package/cjs/connection/portal.js +148 -0
- package/cjs/connection/prepared-statement.js +217 -0
- package/cjs/constants.js +250 -0
- package/cjs/data-type-map.js +119 -0
- package/cjs/data-types/bool-type.js +27 -0
- package/cjs/data-types/box-type.js +52 -0
- package/cjs/data-types/bytea-type.js +29 -0
- package/cjs/data-types/char-type.js +27 -0
- package/cjs/data-types/circle-type.js +48 -0
- package/cjs/data-types/date-type.js +67 -0
- package/cjs/data-types/float4-type.js +25 -0
- package/cjs/data-types/float8-type.js +25 -0
- package/cjs/data-types/int2-type.js +26 -0
- package/cjs/data-types/int2-vector-type.js +38 -0
- package/cjs/data-types/int4-type.js +26 -0
- package/cjs/data-types/int8-type.js +31 -0
- package/cjs/data-types/json-type.js +38 -0
- package/cjs/data-types/jsonb-type.js +42 -0
- package/cjs/data-types/lseg-type.js +52 -0
- package/cjs/data-types/numeric-type.js +125 -0
- package/cjs/data-types/oid-type.js +32 -0
- package/cjs/data-types/point-type.js +39 -0
- package/cjs/data-types/time-type.js +54 -0
- package/cjs/data-types/timestamp-type.js +81 -0
- package/cjs/data-types/timestamptz-type.js +73 -0
- package/cjs/data-types/uuid-type.js +39 -0
- package/cjs/data-types/varchar-type.js +27 -0
- package/cjs/index.js +41 -0
- package/cjs/interfaces/command-result.js +2 -0
- package/cjs/interfaces/data-mapping-options.js +2 -0
- package/cjs/interfaces/data-type.js +2 -0
- package/cjs/interfaces/database-connection-params.js +2 -0
- package/cjs/interfaces/field-info.js +2 -0
- package/cjs/interfaces/query-options.js +2 -0
- package/cjs/interfaces/query-result.js +2 -0
- package/cjs/interfaces/script-execute-options.js +2 -0
- package/cjs/interfaces/script-result.js +2 -0
- package/cjs/interfaces/statement-prepare-options.js +2 -0
- package/cjs/package.json +3 -0
- package/cjs/protocol/backend.js +256 -0
- package/cjs/protocol/buffer-reader.js +78 -0
- package/cjs/protocol/database-error.js +17 -0
- package/cjs/protocol/frontend.js +218 -0
- package/cjs/protocol/pg-socket.js +345 -0
- package/cjs/protocol/protocol.js +71 -0
- package/cjs/protocol/sasl.js +108 -0
- package/cjs/protocol/smart-buffer.js +195 -0
- package/cjs/safe-event-emitter.js +17 -0
- package/cjs/types.js +2 -0
- package/cjs/util/array-calculatedim.js +19 -0
- package/cjs/util/bigint-methods.js +42 -0
- package/cjs/util/config-from-env.js +30 -0
- package/cjs/util/connection-config.js +65 -0
- package/cjs/util/convert-row-to-object.js +13 -0
- package/cjs/util/decode-binaryarray.js +39 -0
- package/cjs/util/encode-binaryarray.js +45 -0
- package/cjs/util/escape-literal.js +27 -0
- package/cjs/util/fast-parseint.js +32 -0
- package/cjs/util/get-parsers.js +42 -0
- package/cjs/util/parse-array.js +61 -0
- package/cjs/util/parse-datetime.js +38 -0
- package/cjs/util/parse-row.js +11 -0
- package/cjs/util/parse-time.js +29 -0
- package/cjs/util/stringify-arrayliteral.js +38 -0
- package/cjs/util/stringify-for-sql.js +30 -0
- package/cjs/util/wrap-row-description.js +35 -0
- package/esm/connection/bind-param.js +6 -0
- package/esm/connection/connection.js +275 -0
- package/esm/connection/cursor.js +86 -0
- package/esm/connection/intl-connection.js +238 -0
- package/esm/connection/pool.js +222 -0
- package/esm/connection/portal.js +144 -0
- package/esm/connection/prepared-statement.js +213 -0
- package/esm/constants.js +247 -0
- package/esm/data-type-map.js +115 -0
- package/esm/data-types/bool-type.js +24 -0
- package/esm/data-types/box-type.js +49 -0
- package/esm/data-types/bytea-type.js +23 -0
- package/esm/data-types/char-type.js +24 -0
- package/esm/data-types/circle-type.js +45 -0
- package/esm/data-types/date-type.js +64 -0
- package/esm/data-types/float4-type.js +22 -0
- package/esm/data-types/float8-type.js +22 -0
- package/esm/data-types/int2-type.js +23 -0
- package/esm/data-types/int2-vector-type.js +35 -0
- package/esm/data-types/int4-type.js +23 -0
- package/esm/data-types/int8-type.js +28 -0
- package/esm/data-types/json-type.js +35 -0
- package/esm/data-types/jsonb-type.js +39 -0
- package/esm/data-types/lseg-type.js +49 -0
- package/esm/data-types/numeric-type.js +121 -0
- package/esm/data-types/oid-type.js +29 -0
- package/esm/data-types/point-type.js +36 -0
- package/esm/data-types/time-type.js +51 -0
- package/esm/data-types/timestamp-type.js +78 -0
- package/esm/data-types/timestamptz-type.js +70 -0
- package/esm/data-types/uuid-type.js +36 -0
- package/esm/data-types/varchar-type.js +24 -0
- package/esm/index.js +25 -0
- package/esm/interfaces/command-result.js +1 -0
- package/esm/interfaces/data-mapping-options.js +1 -0
- package/esm/interfaces/data-type.js +1 -0
- package/esm/interfaces/database-connection-params.js +1 -0
- package/esm/interfaces/field-info.js +1 -0
- package/esm/interfaces/query-options.js +1 -0
- package/esm/interfaces/query-result.js +1 -0
- package/esm/interfaces/script-execute-options.js +1 -0
- package/esm/interfaces/script-result.js +1 -0
- package/esm/interfaces/statement-prepare-options.js +1 -0
- package/esm/protocol/backend.js +252 -0
- package/esm/protocol/buffer-reader.js +74 -0
- package/esm/protocol/database-error.js +13 -0
- package/esm/protocol/frontend.js +214 -0
- package/esm/protocol/pg-socket.js +338 -0
- package/esm/protocol/protocol.js +68 -0
- package/esm/protocol/sasl.js +102 -0
- package/esm/protocol/smart-buffer.js +168 -0
- package/esm/safe-event-emitter.js +13 -0
- package/esm/types.js +1 -0
- package/esm/util/array-calculatedim.js +15 -0
- package/esm/util/bigint-methods.js +37 -0
- package/esm/util/config-from-env.js +26 -0
- package/esm/util/connection-config.js +57 -0
- package/esm/util/convert-row-to-object.js +9 -0
- package/esm/util/decode-binaryarray.js +35 -0
- package/esm/util/encode-binaryarray.js +41 -0
- package/esm/util/escape-literal.js +23 -0
- package/esm/util/fast-parseint.js +28 -0
- package/esm/util/get-parsers.js +38 -0
- package/esm/util/parse-array.js +57 -0
- package/esm/util/parse-datetime.js +34 -0
- package/esm/util/parse-row.js +7 -0
- package/esm/util/parse-time.js +25 -0
- package/esm/util/stringify-arrayliteral.js +34 -0
- package/esm/util/stringify-for-sql.js +25 -0
- package/esm/util/wrap-row-description.js +31 -0
- package/package.json +54 -0
- package/typings/connection/bind-param.d.ts +6 -0
- package/typings/connection/connection.d.ts +110 -0
- package/typings/connection/cursor.d.ts +25 -0
- package/typings/connection/intl-connection.d.ts +40 -0
- package/typings/connection/pool.d.ts +52 -0
- package/typings/connection/portal.d.ts +23 -0
- package/typings/connection/prepared-statement.d.ts +27 -0
- package/typings/constants.d.ts +130 -0
- package/typings/data-type-map.d.ts +11 -0
- package/typings/data-types/bool-type.d.ts +3 -0
- package/typings/data-types/box-type.d.ts +3 -0
- package/typings/data-types/bytea-type.d.ts +3 -0
- package/typings/data-types/char-type.d.ts +3 -0
- package/typings/data-types/circle-type.d.ts +3 -0
- package/typings/data-types/date-type.d.ts +3 -0
- package/typings/data-types/float4-type.d.ts +3 -0
- package/typings/data-types/float8-type.d.ts +3 -0
- package/typings/data-types/int2-type.d.ts +3 -0
- package/typings/data-types/int2-vector-type.d.ts +3 -0
- package/typings/data-types/int4-type.d.ts +3 -0
- package/typings/data-types/int8-type.d.ts +3 -0
- package/typings/data-types/json-type.d.ts +3 -0
- package/typings/data-types/jsonb-type.d.ts +3 -0
- package/typings/data-types/lseg-type.d.ts +3 -0
- package/typings/data-types/numeric-type.d.ts +12 -0
- package/typings/data-types/oid-type.d.ts +4 -0
- package/typings/data-types/point-type.d.ts +3 -0
- package/typings/data-types/time-type.d.ts +3 -0
- package/typings/data-types/timestamp-type.d.ts +3 -0
- package/typings/data-types/timestamptz-type.d.ts +3 -0
- package/typings/data-types/uuid-type.d.ts +3 -0
- package/typings/data-types/varchar-type.d.ts +3 -0
- package/typings/index.d.ts +25 -0
- package/typings/interfaces/command-result.d.ts +28 -0
- package/typings/interfaces/data-mapping-options.d.ts +9 -0
- package/typings/interfaces/data-type.d.ts +31 -0
- package/typings/interfaces/database-connection-params.d.ts +38 -0
- package/typings/interfaces/field-info.d.ts +46 -0
- package/typings/interfaces/query-options.d.ts +46 -0
- package/typings/interfaces/query-result.d.ts +8 -0
- package/typings/interfaces/script-execute-options.d.ts +26 -0
- package/typings/interfaces/script-result.d.ts +15 -0
- package/typings/interfaces/statement-prepare-options.d.ts +13 -0
- package/typings/protocol/backend.d.ts +9 -0
- package/typings/protocol/buffer-reader.d.ts +18 -0
- package/typings/protocol/database-error.d.ts +20 -0
- package/typings/protocol/frontend.d.ts +59 -0
- package/typings/protocol/pg-socket.d.ts +51 -0
- package/typings/protocol/protocol.d.ts +180 -0
- package/typings/protocol/sasl.d.ts +13 -0
- package/typings/protocol/smart-buffer.d.ts +39 -0
- package/typings/safe-event-emitter.d.ts +5 -0
- package/typings/types.d.ts +15 -0
- package/typings/util/array-calculatedim.d.ts +1 -0
- package/typings/util/bigint-methods.d.ts +3 -0
- package/typings/util/config-from-env.d.ts +2 -0
- package/typings/util/connection-config.d.ts +3 -0
- package/typings/util/convert-row-to-object.d.ts +2 -0
- package/typings/util/decode-binaryarray.d.ts +4 -0
- package/typings/util/encode-binaryarray.d.ts +5 -0
- package/typings/util/escape-literal.d.ts +1 -0
- package/typings/util/fast-parseint.d.ts +1 -0
- package/typings/util/get-parsers.d.ts +4 -0
- package/typings/util/parse-array.d.ts +5 -0
- package/typings/util/parse-datetime.d.ts +1 -0
- package/typings/util/parse-row.d.ts +3 -0
- package/typings/util/parse-time.d.ts +3 -0
- package/typings/util/stringify-arrayliteral.d.ts +3 -0
- package/typings/util/stringify-for-sql.d.ts +4 -0
- package/typings/util/wrap-row-description.d.ts +5 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
2
|
+
import { fastParseInt } from './fast-parseint.js';
|
|
3
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
|
+
const TIMESTAMP_PATTERN =
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
/^(\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 INFINITY_PATTERN = /^-?infinity$/;
|
|
8
|
+
export function parseDateTime(str, parseTime, parseTimeZone, utc) {
|
|
9
|
+
let m = str.match(TIMESTAMP_PATTERN);
|
|
10
|
+
if (!m) {
|
|
11
|
+
m = str.match(INFINITY_PATTERN);
|
|
12
|
+
if (m)
|
|
13
|
+
return Number(str.replace('i', 'I'));
|
|
14
|
+
return new Date('invalid');
|
|
15
|
+
}
|
|
16
|
+
const args = [1970, 0, 1, 0, 0, 0, 0];
|
|
17
|
+
const l = parseTime ? 7 : 3;
|
|
18
|
+
for (let i = 0; i < l; i++) {
|
|
19
|
+
const s = m[i + 1];
|
|
20
|
+
args[i] = fastParseInt(s) || 0;
|
|
21
|
+
}
|
|
22
|
+
// Months starts from 0
|
|
23
|
+
if (args[1] > 0)
|
|
24
|
+
args[1]--;
|
|
25
|
+
if (parseTimeZone && parseTime && m[9]) {
|
|
26
|
+
const r = m[9] === '-' ? -1 : 1;
|
|
27
|
+
args[3] -= (fastParseInt(m[10]) || 0) * r;
|
|
28
|
+
args[4] -= (fastParseInt(m[11]) || 0) * r;
|
|
29
|
+
return new Date(Date.UTC(...args));
|
|
30
|
+
}
|
|
31
|
+
if (m[8] || utc)
|
|
32
|
+
return new Date(Date.UTC(...args));
|
|
33
|
+
return new Date(...args);
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { fastParseInt } from './fast-parseint.js';
|
|
2
|
+
// eslint-disable-next-line
|
|
3
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
4
|
+
export const 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])?))?$/;
|
|
5
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
6
|
+
export const 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])?))?$/;
|
|
7
|
+
export function parseTime(str, parseTimeZone, utc) {
|
|
8
|
+
const m = str.match(TIME_PATTERN);
|
|
9
|
+
if (!m)
|
|
10
|
+
return new Date('invalid');
|
|
11
|
+
const args = [1970, 0, 1, 0, 0, 0, 0];
|
|
12
|
+
for (let i = 1; i < 4; i++) {
|
|
13
|
+
const s = m[i];
|
|
14
|
+
args[i + 2] = fastParseInt(s) || 0;
|
|
15
|
+
}
|
|
16
|
+
if (parseTimeZone && m[6]) {
|
|
17
|
+
const r = m[9] === '-' ? -1 : 1;
|
|
18
|
+
args[3] -= (fastParseInt(m[7]) || 0) * r;
|
|
19
|
+
args[4] -= (fastParseInt(m[8]) || 0) * r;
|
|
20
|
+
return new Date(Date.UTC(...args));
|
|
21
|
+
}
|
|
22
|
+
if (m[5] || utc)
|
|
23
|
+
return new Date(Date.UTC(...args));
|
|
24
|
+
return new Date(...args);
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { arrayCalculateDim } from './array-calculatedim.js';
|
|
2
|
+
export function stringifyArrayLiteral(value, options, encode) {
|
|
3
|
+
const dim = arrayCalculateDim(value);
|
|
4
|
+
const writeDim = (arr, level) => {
|
|
5
|
+
const elemCount = dim[level];
|
|
6
|
+
const out = [];
|
|
7
|
+
for (let i = 0; i < elemCount; i++) {
|
|
8
|
+
let x = arr && arr[i];
|
|
9
|
+
if (level < dim.length - 1) {
|
|
10
|
+
if (x != null && !Array.isArray(x))
|
|
11
|
+
x = [x];
|
|
12
|
+
out.push(writeDim(x, level + 1));
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
// if value is null
|
|
16
|
+
if (x == null) {
|
|
17
|
+
out.push('NULL');
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(x)) {
|
|
21
|
+
out.push(stringifyArrayLiteral(x, options, encode));
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (encode)
|
|
25
|
+
x = encode(x, options || {});
|
|
26
|
+
out.push(escapeArrayItem('' + x));
|
|
27
|
+
}
|
|
28
|
+
return '{' + out.join(',') + '}';
|
|
29
|
+
};
|
|
30
|
+
return writeDim(value, 0);
|
|
31
|
+
}
|
|
32
|
+
function escapeArrayItem(str) {
|
|
33
|
+
return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UuidType } from '../data-types/uuid-type.js';
|
|
2
|
+
import { escapeLiteral } from './escape-literal.js';
|
|
3
|
+
export function stringifyArrayForSQL(v, options, encode) {
|
|
4
|
+
const arr = v.map(x => stringifyValueForSQL(x, options, encode));
|
|
5
|
+
return 'ARRAY[' + arr.join(',') + ']';
|
|
6
|
+
}
|
|
7
|
+
export function stringifyValueForSQL(v, options, encode) {
|
|
8
|
+
if (v == null)
|
|
9
|
+
return 'null';
|
|
10
|
+
if (typeof v === 'boolean')
|
|
11
|
+
return v ? 'true' : 'false';
|
|
12
|
+
if (Array.isArray(v))
|
|
13
|
+
return stringifyArrayForSQL(v, options, encode);
|
|
14
|
+
if (encode)
|
|
15
|
+
v = encode(v, options || {});
|
|
16
|
+
if (typeof v === 'number')
|
|
17
|
+
return '' + v;
|
|
18
|
+
if (typeof v === 'bigint')
|
|
19
|
+
return v.toString();
|
|
20
|
+
if (typeof v === 'string' && UuidType.isType(v))
|
|
21
|
+
return escapeLiteral('' + v) + '::uuid';
|
|
22
|
+
if (typeof v === 'object')
|
|
23
|
+
return escapeLiteral(JSON.stringify(v)) + '::json';
|
|
24
|
+
return escapeLiteral('' + v);
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DataFormat, DataTypeNames } from '../constants.js';
|
|
2
|
+
export function wrapRowDescription(typeMap, fields, columnFormat) {
|
|
3
|
+
return fields.map((f, idx) => {
|
|
4
|
+
const cf = Array.isArray(columnFormat) ? columnFormat[idx] : columnFormat;
|
|
5
|
+
const x = {
|
|
6
|
+
fieldName: f.fieldName,
|
|
7
|
+
tableId: f.tableId,
|
|
8
|
+
columnId: f.columnId,
|
|
9
|
+
dataTypeId: f.dataTypeId,
|
|
10
|
+
dataTypeName: DataTypeNames[f.dataTypeId] || '',
|
|
11
|
+
jsType: cf === DataFormat.binary ? 'Buffer' : 'string',
|
|
12
|
+
};
|
|
13
|
+
x.isArray = x.dataTypeName.startsWith('_');
|
|
14
|
+
if (x.isArray) {
|
|
15
|
+
x.elementDataTypeName = x.dataTypeName.substring(1);
|
|
16
|
+
for (const oid of Object.keys(DataTypeNames)) {
|
|
17
|
+
if (DataTypeNames[oid] === x.elementDataTypeName)
|
|
18
|
+
x.elementDataTypeId = parseInt(oid, 10);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (f.fixedSize && f.fixedSize > 0)
|
|
22
|
+
x.fixedSize = f.fixedSize;
|
|
23
|
+
if (f.modifier && f.modifier > 0)
|
|
24
|
+
x.modifier = f.modifier;
|
|
25
|
+
const reg = typeMap.get(x.dataTypeId);
|
|
26
|
+
if (reg) {
|
|
27
|
+
x.jsType = reg.jsType;
|
|
28
|
+
}
|
|
29
|
+
return x;
|
|
30
|
+
});
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "postgrejs",
|
|
3
|
+
"description": "Enterprise level PostgreSQL client for JavaScript",
|
|
4
|
+
"version": "2.12.0",
|
|
5
|
+
"author": "Panates",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/panates/postgresql-client.git"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./cjs/index.js",
|
|
16
|
+
"module": "./esm/index.js",
|
|
17
|
+
"types": "typings/index.d.ts",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"doublylinked": "^2.5.4",
|
|
20
|
+
"lightning-pool": "^4.2.2",
|
|
21
|
+
"postgres-bytea": "^3.0.0",
|
|
22
|
+
"power-tasks": "^1.7.3",
|
|
23
|
+
"putil-merge": "^3.12.1",
|
|
24
|
+
"putil-promisify": "^1.10.1",
|
|
25
|
+
"putil-varhelpers": "^1.6.5"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=16.0"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"cjs/",
|
|
32
|
+
"esm/",
|
|
33
|
+
"typings/",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md",
|
|
36
|
+
"CHANGELOG.md"
|
|
37
|
+
],
|
|
38
|
+
"keywords": [
|
|
39
|
+
"postgresql",
|
|
40
|
+
"postgres",
|
|
41
|
+
"postgre",
|
|
42
|
+
"pg",
|
|
43
|
+
"database",
|
|
44
|
+
"db",
|
|
45
|
+
"driver",
|
|
46
|
+
"client",
|
|
47
|
+
"backend",
|
|
48
|
+
"rdbms",
|
|
49
|
+
"sql",
|
|
50
|
+
"typescript",
|
|
51
|
+
"ts",
|
|
52
|
+
"esm"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ConnectionState } from '../constants.js';
|
|
3
|
+
import { ConnectionConfiguration } from '../interfaces/database-connection-params.js';
|
|
4
|
+
import { QueryOptions } from '../interfaces/query-options.js';
|
|
5
|
+
import { QueryResult } from '../interfaces/query-result.js';
|
|
6
|
+
import { ScriptExecuteOptions } from '../interfaces/script-execute-options.js';
|
|
7
|
+
import { ScriptResult } from '../interfaces/script-result.js';
|
|
8
|
+
import { StatementPrepareOptions } from '../interfaces/statement-prepare-options.js';
|
|
9
|
+
import { DatabaseError } from '../protocol/database-error.js';
|
|
10
|
+
import { Protocol } from '../protocol/protocol.js';
|
|
11
|
+
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
12
|
+
import { Maybe } from '../types.js';
|
|
13
|
+
import { IntlConnection } from './intl-connection.js';
|
|
14
|
+
import type { Pool } from './pool.js';
|
|
15
|
+
import { PreparedStatement } from './prepared-statement.js';
|
|
16
|
+
export type NotificationMessage = Protocol.NotificationResponseMessage;
|
|
17
|
+
export type NotificationCallback = (msg: NotificationMessage) => any;
|
|
18
|
+
export declare class Connection extends SafeEventEmitter implements AsyncDisposable {
|
|
19
|
+
protected readonly _pool?: Pool;
|
|
20
|
+
protected readonly _intlCon: IntlConnection;
|
|
21
|
+
protected readonly _notificationListeners: SafeEventEmitter;
|
|
22
|
+
protected _closing: boolean;
|
|
23
|
+
constructor(pool: Pool, intlCon: IntlConnection);
|
|
24
|
+
constructor(config?: ConnectionConfiguration | string);
|
|
25
|
+
/**
|
|
26
|
+
* Returns configuration object
|
|
27
|
+
*/
|
|
28
|
+
get config(): ConnectionConfiguration;
|
|
29
|
+
/**
|
|
30
|
+
* Returns true if connection is in a transaction
|
|
31
|
+
*/
|
|
32
|
+
get inTransaction(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Returns current state of the connection
|
|
35
|
+
*/
|
|
36
|
+
get state(): ConnectionState;
|
|
37
|
+
/**
|
|
38
|
+
* Returns processId of current session
|
|
39
|
+
*/
|
|
40
|
+
get processID(): Maybe<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns information parameters for current session
|
|
43
|
+
*/
|
|
44
|
+
get sessionParameters(): Record<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns secret key of current session
|
|
47
|
+
*/
|
|
48
|
+
get secretKey(): Maybe<number>;
|
|
49
|
+
/**
|
|
50
|
+
* Connects to the server
|
|
51
|
+
*/
|
|
52
|
+
connect(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Closes connection. You can define how long time the connection will
|
|
55
|
+
* wait for active queries before terminating the connection.
|
|
56
|
+
* On the end of the given time, it forces to close the socket and than emits `terminate` event.
|
|
57
|
+
*
|
|
58
|
+
* @param terminateWait {number} - Determines how long the connection will wait for active queries before terminating.
|
|
59
|
+
*/
|
|
60
|
+
close(terminateWait?: number): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Executes single or multiple SQL scripts using Simple Query protocol.
|
|
63
|
+
*
|
|
64
|
+
* @param sql {string} - SQL script that will be executed
|
|
65
|
+
* @param options {ScriptExecuteOptions} - Execute options
|
|
66
|
+
*/
|
|
67
|
+
execute(sql: string, options?: ScriptExecuteOptions): Promise<ScriptResult>;
|
|
68
|
+
query(sql: string, options?: QueryOptions): Promise<QueryResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a PreparedStatement instance
|
|
71
|
+
* @param sql {string} - SQL script that will be executed
|
|
72
|
+
* @param options {StatementPrepareOptions} - Options
|
|
73
|
+
*/
|
|
74
|
+
prepare(sql: string, options?: StatementPrepareOptions): Promise<PreparedStatement>;
|
|
75
|
+
/**
|
|
76
|
+
* Starts a transaction
|
|
77
|
+
*/
|
|
78
|
+
startTransaction(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Commits current transaction
|
|
81
|
+
*/
|
|
82
|
+
commit(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Rolls back current transaction
|
|
85
|
+
*/
|
|
86
|
+
rollback(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Starts transaction and creates a savepoint
|
|
89
|
+
* @param name {string} - Name of the savepoint
|
|
90
|
+
*/
|
|
91
|
+
savepoint(name: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Rolls back current transaction to given savepoint
|
|
94
|
+
* @param name {string} - Name of the savepoint
|
|
95
|
+
*/
|
|
96
|
+
rollbackToSavepoint(name: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Releases savepoint
|
|
99
|
+
* @param name {string} - Name of the savepoint
|
|
100
|
+
*/
|
|
101
|
+
releaseSavepoint(name: string): Promise<void>;
|
|
102
|
+
listen(channel: string, callback: NotificationCallback): Promise<void>;
|
|
103
|
+
unListen(channel: string): Promise<void>;
|
|
104
|
+
unListenAll(): Promise<void>;
|
|
105
|
+
protected _handleNotification(msg: NotificationMessage): void;
|
|
106
|
+
protected _close(): Promise<void>;
|
|
107
|
+
protected _handleError(err: DatabaseError, script: string): DatabaseError;
|
|
108
|
+
protected _captureErrorStack<T>(promise: Promise<T>): Promise<T>;
|
|
109
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
110
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FieldInfo } from '../interfaces/field-info.js';
|
|
3
|
+
import { QueryOptions } from '../interfaces/query-options.js';
|
|
4
|
+
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
5
|
+
import { AnyParseFunction, Maybe, Row } from '../types.js';
|
|
6
|
+
import { Portal } from './portal.js';
|
|
7
|
+
import { PreparedStatement } from './prepared-statement.js';
|
|
8
|
+
export declare class Cursor extends SafeEventEmitter implements AsyncDisposable {
|
|
9
|
+
private readonly _statement;
|
|
10
|
+
private readonly _portal;
|
|
11
|
+
private readonly _parsers;
|
|
12
|
+
private readonly _queryOptions;
|
|
13
|
+
private _taskQueue;
|
|
14
|
+
private _rows;
|
|
15
|
+
private _closed;
|
|
16
|
+
readonly fields: FieldInfo[];
|
|
17
|
+
constructor(statement: PreparedStatement, portal: Portal, fields: FieldInfo[], parsers: AnyParseFunction[], queryOptions: QueryOptions);
|
|
18
|
+
get rowType(): 'array' | 'object';
|
|
19
|
+
get isClosed(): boolean;
|
|
20
|
+
next(): Promise<Maybe<Row>>;
|
|
21
|
+
fetch(nRows: number): Promise<Row[]>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
private _fetchRows;
|
|
24
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TaskQueue } from 'power-tasks';
|
|
2
|
+
import { ConnectionState } from '../constants.js';
|
|
3
|
+
import { ConnectionConfiguration } from '../interfaces/database-connection-params.js';
|
|
4
|
+
import { ScriptExecuteOptions } from '../interfaces/script-execute-options.js';
|
|
5
|
+
import { ScriptResult } from '../interfaces/script-result.js';
|
|
6
|
+
import { PgSocket } from '../protocol/pg-socket.js';
|
|
7
|
+
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
8
|
+
import { Maybe } from '../types.js';
|
|
9
|
+
import { Connection } from './connection.js';
|
|
10
|
+
export declare class IntlConnection extends SafeEventEmitter {
|
|
11
|
+
protected _refCount: number;
|
|
12
|
+
protected _config: ConnectionConfiguration;
|
|
13
|
+
protected _onErrorSavePoint: string;
|
|
14
|
+
transactionStatus: string;
|
|
15
|
+
socket: PgSocket;
|
|
16
|
+
statementQueue: TaskQueue;
|
|
17
|
+
constructor(config?: ConnectionConfiguration | string);
|
|
18
|
+
get config(): ConnectionConfiguration;
|
|
19
|
+
get inTransaction(): boolean;
|
|
20
|
+
get state(): ConnectionState;
|
|
21
|
+
get refCount(): number;
|
|
22
|
+
get processID(): Maybe<number>;
|
|
23
|
+
get secretKey(): Maybe<number>;
|
|
24
|
+
get sessionParameters(): Record<string, string>;
|
|
25
|
+
connect(): Promise<void>;
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
execute(sql: string, options?: ScriptExecuteOptions, cb?: (event: string, ...args: any[]) => void): Promise<ScriptResult>;
|
|
28
|
+
startTransaction(): Promise<void>;
|
|
29
|
+
savepoint(name: string): Promise<void>;
|
|
30
|
+
commit(): Promise<void>;
|
|
31
|
+
rollback(): Promise<void>;
|
|
32
|
+
rollbackToSavepoint(name: string): Promise<void>;
|
|
33
|
+
releaseSavepoint(name: string): Promise<void>;
|
|
34
|
+
ref(): void;
|
|
35
|
+
unref(): boolean;
|
|
36
|
+
assertConnected(): void;
|
|
37
|
+
protected _execute(sql: string, options?: ScriptExecuteOptions, cb?: (event: string, ...args: any[]) => void): Promise<ScriptResult>;
|
|
38
|
+
protected _onError(err: Error): void;
|
|
39
|
+
}
|
|
40
|
+
export declare function getIntlConnection(connection: Connection): IntlConnection;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Pool as LightningPool } from 'lightning-pool';
|
|
2
|
+
import { PoolConfiguration } from '../interfaces/database-connection-params.js';
|
|
3
|
+
import { QueryOptions } from '../interfaces/query-options.js';
|
|
4
|
+
import { QueryResult } from '../interfaces/query-result.js';
|
|
5
|
+
import { ScriptExecuteOptions } from '../interfaces/script-execute-options.js';
|
|
6
|
+
import { ScriptResult } from '../interfaces/script-result.js';
|
|
7
|
+
import { StatementPrepareOptions } from '../interfaces/statement-prepare-options.js';
|
|
8
|
+
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
9
|
+
import { Connection, NotificationCallback } from './connection.js';
|
|
10
|
+
import { IntlConnection } from './intl-connection.js';
|
|
11
|
+
import { PreparedStatement } from './prepared-statement.js';
|
|
12
|
+
export declare class Pool extends SafeEventEmitter {
|
|
13
|
+
protected readonly _pool: LightningPool<IntlConnection>;
|
|
14
|
+
protected readonly _notificationListeners: SafeEventEmitter;
|
|
15
|
+
protected _notificationConnection?: Connection;
|
|
16
|
+
readonly config: PoolConfiguration;
|
|
17
|
+
constructor(config?: PoolConfiguration | string);
|
|
18
|
+
/**
|
|
19
|
+
* Returns number of connections that are currently acquired
|
|
20
|
+
*/
|
|
21
|
+
get acquiredConnections(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Returns number of unused connections in the pool
|
|
24
|
+
*/
|
|
25
|
+
get idleConnections(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Returns total number of connections in the pool regardless of whether they are idle or in use
|
|
28
|
+
*/
|
|
29
|
+
get totalConnections(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Obtains a connection from the connection pool
|
|
32
|
+
*/
|
|
33
|
+
acquire(): Promise<Connection>;
|
|
34
|
+
/**
|
|
35
|
+
* Shuts down the pool and destroys all resources.
|
|
36
|
+
*/
|
|
37
|
+
close(terminateWait?: number): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Executes a script
|
|
40
|
+
*/
|
|
41
|
+
execute(sql: string, options?: ScriptExecuteOptions): Promise<ScriptResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Executes a query
|
|
44
|
+
*/
|
|
45
|
+
query(sql: string, options?: QueryOptions): Promise<QueryResult>;
|
|
46
|
+
prepare(sql: string, options?: StatementPrepareOptions): Promise<PreparedStatement>;
|
|
47
|
+
release(connection: Connection): Promise<void>;
|
|
48
|
+
listen(channel: string, callback: NotificationCallback): Promise<void>;
|
|
49
|
+
unListen(channel: string): Promise<void>;
|
|
50
|
+
unListenAll(): Promise<void>;
|
|
51
|
+
protected _initNotificationConnection(): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { QueryOptions } from '../interfaces/query-options.js';
|
|
2
|
+
import { Protocol } from '../protocol/protocol.js';
|
|
3
|
+
import { Maybe } from '../types.js';
|
|
4
|
+
import { Connection } from './connection.js';
|
|
5
|
+
import type { PreparedStatement } from './prepared-statement.js';
|
|
6
|
+
export interface PortalExecuteResult {
|
|
7
|
+
code: Protocol.BackendMessageCode;
|
|
8
|
+
rows?: any[];
|
|
9
|
+
command?: string;
|
|
10
|
+
rowCount?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class Portal {
|
|
13
|
+
private readonly _statement;
|
|
14
|
+
private readonly _name?;
|
|
15
|
+
private _columnFormat;
|
|
16
|
+
constructor(statement: PreparedStatement, name: string);
|
|
17
|
+
get connection(): Connection;
|
|
18
|
+
get name(): Maybe<string>;
|
|
19
|
+
bind(params: Maybe<any[]>, queryOptions: QueryOptions): Promise<void>;
|
|
20
|
+
retrieveFields(): Promise<Protocol.RowDescription[]>;
|
|
21
|
+
execute(fetchCount?: number): Promise<PortalExecuteResult>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { QueryOptions } from '../interfaces/query-options.js';
|
|
3
|
+
import { QueryResult } from '../interfaces/query-result.js';
|
|
4
|
+
import { StatementPrepareOptions } from '../interfaces/statement-prepare-options.js';
|
|
5
|
+
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
6
|
+
import { Maybe, OID } from '../types.js';
|
|
7
|
+
import { Connection } from './connection.js';
|
|
8
|
+
export declare class PreparedStatement extends SafeEventEmitter implements AsyncDisposable {
|
|
9
|
+
private readonly _connection;
|
|
10
|
+
private readonly _sql;
|
|
11
|
+
private readonly _name;
|
|
12
|
+
private readonly _paramTypes;
|
|
13
|
+
protected _onErrorSavePoint: string;
|
|
14
|
+
private _refCount;
|
|
15
|
+
constructor(connection: Connection, sql: string, paramTypes?: OID[]);
|
|
16
|
+
static prepare(connection: Connection, sql: string, options?: StatementPrepareOptions): Promise<PreparedStatement>;
|
|
17
|
+
get connection(): Connection;
|
|
18
|
+
get name(): Maybe<string>;
|
|
19
|
+
get sql(): string;
|
|
20
|
+
get paramTypes(): Maybe<Maybe<OID>[]>;
|
|
21
|
+
execute(options?: QueryOptions): Promise<QueryResult>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
cancel(): Promise<void>;
|
|
24
|
+
protected _execute(options?: QueryOptions): Promise<QueryResult>;
|
|
25
|
+
protected _close(): Promise<void>;
|
|
26
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Protocol } from './protocol/protocol.js';
|
|
2
|
+
import DataFormat = Protocol.DataFormat;
|
|
3
|
+
export { DataFormat };
|
|
4
|
+
export declare const DEFAULT_COLUMN_FORMAT = DataFormat.binary;
|
|
5
|
+
export declare enum ConnectionState {
|
|
6
|
+
CLOSED = 0,
|
|
7
|
+
CONNECTING = 1,
|
|
8
|
+
AUTHORIZING = 3,
|
|
9
|
+
READY = 2,
|
|
10
|
+
CLOSING = 10
|
|
11
|
+
}
|
|
12
|
+
export declare const DataTypeOIDs: {
|
|
13
|
+
bool: number;
|
|
14
|
+
bytea: number;
|
|
15
|
+
char: number;
|
|
16
|
+
name: number;
|
|
17
|
+
int8: number;
|
|
18
|
+
int2: number;
|
|
19
|
+
int2vector: number;
|
|
20
|
+
int4: number;
|
|
21
|
+
regproc: number;
|
|
22
|
+
text: number;
|
|
23
|
+
oid: number;
|
|
24
|
+
tid: number;
|
|
25
|
+
xid: number;
|
|
26
|
+
cid: number;
|
|
27
|
+
oidvector: number;
|
|
28
|
+
json: number;
|
|
29
|
+
xml: number;
|
|
30
|
+
point: number;
|
|
31
|
+
lseg: number;
|
|
32
|
+
path: number;
|
|
33
|
+
box: number;
|
|
34
|
+
polygon: number;
|
|
35
|
+
line: number;
|
|
36
|
+
cidr: number;
|
|
37
|
+
float4: number;
|
|
38
|
+
float8: number;
|
|
39
|
+
unknown: number;
|
|
40
|
+
circle: number;
|
|
41
|
+
macaddr8: number;
|
|
42
|
+
money: number;
|
|
43
|
+
macaddr: number;
|
|
44
|
+
inet: number;
|
|
45
|
+
bpchar: number;
|
|
46
|
+
varchar: number;
|
|
47
|
+
date: number;
|
|
48
|
+
time: number;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
timestamptz: number;
|
|
51
|
+
interval: number;
|
|
52
|
+
timetz: number;
|
|
53
|
+
bit: number;
|
|
54
|
+
varbit: number;
|
|
55
|
+
numeric: number;
|
|
56
|
+
refcursor: number;
|
|
57
|
+
regprocedure: number;
|
|
58
|
+
regoper: number;
|
|
59
|
+
regoperator: number;
|
|
60
|
+
regclass: number;
|
|
61
|
+
regtype: number;
|
|
62
|
+
record: number;
|
|
63
|
+
cstring: number;
|
|
64
|
+
any: number;
|
|
65
|
+
anyarray: number;
|
|
66
|
+
void: number;
|
|
67
|
+
trigger: number;
|
|
68
|
+
language_handler: number;
|
|
69
|
+
internal: number;
|
|
70
|
+
anyelement: number;
|
|
71
|
+
anynonarray: number;
|
|
72
|
+
uuid: number;
|
|
73
|
+
jsonb: number;
|
|
74
|
+
anyrange: number;
|
|
75
|
+
int4range: number;
|
|
76
|
+
numrange: number;
|
|
77
|
+
tsrange: number;
|
|
78
|
+
rstzrange: number;
|
|
79
|
+
daterange: number;
|
|
80
|
+
int8range: number;
|
|
81
|
+
_xml: number;
|
|
82
|
+
_json: number;
|
|
83
|
+
_xid8: number;
|
|
84
|
+
_line: number;
|
|
85
|
+
_cidr: number;
|
|
86
|
+
_circle: number;
|
|
87
|
+
_macaddr8: number;
|
|
88
|
+
_money: number;
|
|
89
|
+
_bool: number;
|
|
90
|
+
_bytea: number;
|
|
91
|
+
_char: number;
|
|
92
|
+
_name: number;
|
|
93
|
+
_int2: number;
|
|
94
|
+
_int2vector: number;
|
|
95
|
+
_int4: number;
|
|
96
|
+
_regproc: number;
|
|
97
|
+
_text: number;
|
|
98
|
+
_tid: number;
|
|
99
|
+
_xid: number;
|
|
100
|
+
_cid: number;
|
|
101
|
+
_oidvector: number;
|
|
102
|
+
_bpchar: number;
|
|
103
|
+
_varchar: number;
|
|
104
|
+
_int8: number;
|
|
105
|
+
_point: number;
|
|
106
|
+
_lseg: number;
|
|
107
|
+
_path: number;
|
|
108
|
+
_box: number;
|
|
109
|
+
_float4: number;
|
|
110
|
+
_float8: number;
|
|
111
|
+
_polygon: number;
|
|
112
|
+
_oid: number;
|
|
113
|
+
_macaddr: number;
|
|
114
|
+
_inet: number;
|
|
115
|
+
_timestamp: number;
|
|
116
|
+
_date: number;
|
|
117
|
+
_time: number;
|
|
118
|
+
_timestamptz: number;
|
|
119
|
+
_interval: number;
|
|
120
|
+
_numeric: number;
|
|
121
|
+
_cstring: number;
|
|
122
|
+
_timetz: number;
|
|
123
|
+
_bit: number;
|
|
124
|
+
_varbit: number;
|
|
125
|
+
_uuid: number;
|
|
126
|
+
_jsonb: number;
|
|
127
|
+
};
|
|
128
|
+
export declare const DataTypeNames: {
|
|
129
|
+
[x: number]: string;
|
|
130
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DataType } from './interfaces/data-type.js';
|
|
2
|
+
import { OID } from './types.js';
|
|
3
|
+
export declare class DataTypeMap {
|
|
4
|
+
private _itemsByOID;
|
|
5
|
+
private _items;
|
|
6
|
+
constructor(other?: DataTypeMap);
|
|
7
|
+
get(oid: OID): DataType;
|
|
8
|
+
register(dataTypes: DataType | DataType[]): void;
|
|
9
|
+
determine(value: any): OID;
|
|
10
|
+
}
|
|
11
|
+
export declare const GlobalTypeMap: DataTypeMap;
|