postgrejs 2.22.9 → 2.23.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 +8 -1
- package/{esm/connection → connection}/bind-param.js +2 -0
- package/{esm/connection → connection}/connection.js +4 -2
- package/{esm/connection → connection}/cursor.js +8 -3
- package/{esm/connection → connection}/intl-connection.js +6 -3
- package/{esm/connection → connection}/pool.js +4 -1
- package/{esm/connection → connection}/portal.js +3 -1
- package/{esm/connection → connection}/prepared-statement.js +6 -3
- package/{esm/constants.js → constants.js} +1 -1
- package/{esm/data-type-map.js → data-type-map.js} +2 -2
- package/package.json +12 -31
- package/{esm/protocol → protocol}/backend.js +1 -0
- package/{esm/protocol → protocol}/buffer-reader.js +2 -1
- package/{esm/protocol → protocol}/database-error.js +16 -0
- package/{esm/protocol → protocol}/frontend.js +1 -0
- package/{esm/protocol → protocol}/pg-socket.js +9 -3
- package/{esm/protocol → protocol}/smart-buffer.js +9 -5
- package/{esm/util → util}/bigint-methods.js +1 -0
- package/cjs/connection/bind-param.js +0 -10
- package/cjs/connection/connection.js +0 -295
- package/cjs/connection/cursor.js +0 -91
- package/cjs/connection/intl-connection.js +0 -258
- package/cjs/connection/pool.js +0 -236
- package/cjs/connection/portal.js +0 -157
- package/cjs/connection/prepared-statement.js +0 -226
- package/cjs/constants.js +0 -249
- package/cjs/data-type-map.js +0 -131
- package/cjs/data-types/bool-type.js +0 -33
- package/cjs/data-types/box-type.js +0 -52
- package/cjs/data-types/bytea-type.js +0 -28
- package/cjs/data-types/char-type.js +0 -27
- package/cjs/data-types/circle-type.js +0 -51
- package/cjs/data-types/date-type.js +0 -75
- package/cjs/data-types/float4-type.js +0 -25
- package/cjs/data-types/float8-type.js +0 -25
- package/cjs/data-types/int2-type.js +0 -26
- package/cjs/data-types/int2-vector-type.js +0 -42
- package/cjs/data-types/int4-type.js +0 -28
- package/cjs/data-types/int8-type.js +0 -36
- package/cjs/data-types/json-type.js +0 -40
- package/cjs/data-types/jsonb-type.js +0 -44
- package/cjs/data-types/lseg-type.js +0 -55
- package/cjs/data-types/numeric-type.js +0 -125
- package/cjs/data-types/oid-type.js +0 -32
- package/cjs/data-types/point-type.js +0 -42
- package/cjs/data-types/time-type.js +0 -66
- package/cjs/data-types/timestamp-type.js +0 -89
- package/cjs/data-types/timestamptz-type.js +0 -76
- package/cjs/data-types/uuid-type.js +0 -39
- package/cjs/data-types/varchar-type.js +0 -27
- package/cjs/index.js +0 -28
- package/cjs/interfaces/command-result.js +0 -2
- package/cjs/interfaces/data-mapping-options.js +0 -2
- package/cjs/interfaces/data-type.js +0 -2
- package/cjs/interfaces/database-connection-params.js +0 -2
- package/cjs/interfaces/field-info.js +0 -2
- package/cjs/interfaces/query-options.js +0 -2
- package/cjs/interfaces/query-result.js +0 -2
- package/cjs/interfaces/script-execute-options.js +0 -2
- package/cjs/interfaces/script-result.js +0 -2
- package/cjs/interfaces/statement-prepare-options.js +0 -2
- package/cjs/package.json +0 -3
- package/cjs/protocol/backend.js +0 -262
- package/cjs/protocol/buffer-reader.js +0 -78
- package/cjs/protocol/database-error.js +0 -17
- package/cjs/protocol/frontend.js +0 -255
- package/cjs/protocol/pg-socket.js +0 -367
- package/cjs/protocol/protocol.js +0 -71
- package/cjs/protocol/sasl.js +0 -108
- package/cjs/protocol/smart-buffer.js +0 -178
- package/cjs/safe-event-emitter.js +0 -17
- package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
- package/cjs/types.js +0 -2
- package/cjs/util/array-calculatedim.js +0 -18
- package/cjs/util/bigint-methods.js +0 -44
- package/cjs/util/config-from-env.js +0 -29
- package/cjs/util/connection-config.js +0 -61
- package/cjs/util/convert-row-to-object.js +0 -12
- package/cjs/util/decode-binaryarray.js +0 -38
- package/cjs/util/encode-binaryarray.js +0 -44
- package/cjs/util/escape-literal.js +0 -26
- package/cjs/util/fast-parseint.js +0 -31
- package/cjs/util/get-parsers.js +0 -41
- package/cjs/util/parse-array.js +0 -60
- package/cjs/util/parse-datetime.js +0 -37
- package/cjs/util/parse-row.js +0 -11
- package/cjs/util/parse-time.js +0 -30
- package/cjs/util/stringify-arrayliteral.js +0 -37
- package/cjs/util/stringify-for-sql.js +0 -29
- package/cjs/util/wrap-row-description.js +0 -34
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -25
- /package/{types/connection → connection}/bind-param.d.ts +0 -0
- /package/{types/connection → connection}/connection.d.ts +0 -0
- /package/{types/connection → connection}/cursor.d.ts +0 -0
- /package/{types/connection → connection}/intl-connection.d.ts +0 -0
- /package/{types/connection → connection}/pool.d.ts +0 -0
- /package/{types/connection → connection}/portal.d.ts +0 -0
- /package/{types/connection → connection}/prepared-statement.d.ts +0 -0
- /package/{types/constants.d.ts → constants.d.ts} +0 -0
- /package/{types/data-type-map.d.ts → data-type-map.d.ts} +0 -0
- /package/{types/data-types → data-types}/bool-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/bool-type.js +0 -0
- /package/{types/data-types → data-types}/box-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/box-type.js +0 -0
- /package/{types/data-types → data-types}/bytea-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/bytea-type.js +0 -0
- /package/{types/data-types → data-types}/char-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/char-type.js +0 -0
- /package/{types/data-types → data-types}/circle-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/circle-type.js +0 -0
- /package/{types/data-types → data-types}/date-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/date-type.js +0 -0
- /package/{types/data-types → data-types}/float4-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/float4-type.js +0 -0
- /package/{types/data-types → data-types}/float8-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/float8-type.js +0 -0
- /package/{types/data-types → data-types}/int2-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int2-type.js +0 -0
- /package/{types/data-types → data-types}/int2-vector-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int2-vector-type.js +0 -0
- /package/{types/data-types → data-types}/int4-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int4-type.js +0 -0
- /package/{types/data-types → data-types}/int8-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/int8-type.js +0 -0
- /package/{types/data-types → data-types}/json-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/json-type.js +0 -0
- /package/{types/data-types → data-types}/jsonb-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/jsonb-type.js +0 -0
- /package/{types/data-types → data-types}/lseg-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/lseg-type.js +0 -0
- /package/{types/data-types → data-types}/numeric-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/numeric-type.js +0 -0
- /package/{types/data-types → data-types}/oid-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/oid-type.js +0 -0
- /package/{types/data-types → data-types}/point-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/point-type.js +0 -0
- /package/{types/data-types → data-types}/time-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/time-type.js +0 -0
- /package/{types/data-types → data-types}/timestamp-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/timestamp-type.js +0 -0
- /package/{types/data-types → data-types}/timestamptz-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/timestamptz-type.js +0 -0
- /package/{types/data-types → data-types}/uuid-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/uuid-type.js +0 -0
- /package/{types/data-types → data-types}/varchar-type.d.ts +0 -0
- /package/{esm/data-types → data-types}/varchar-type.js +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/interfaces → interfaces}/command-result.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/command-result.js +0 -0
- /package/{types/interfaces → interfaces}/data-mapping-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/data-mapping-options.js +0 -0
- /package/{types/interfaces → interfaces}/data-type.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/data-type.js +0 -0
- /package/{types/interfaces → interfaces}/database-connection-params.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/database-connection-params.js +0 -0
- /package/{types/interfaces → interfaces}/field-info.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/field-info.js +0 -0
- /package/{types/interfaces → interfaces}/query-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/query-options.js +0 -0
- /package/{types/interfaces → interfaces}/query-result.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/query-result.js +0 -0
- /package/{types/interfaces → interfaces}/script-execute-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/script-execute-options.js +0 -0
- /package/{types/interfaces → interfaces}/script-result.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/script-result.js +0 -0
- /package/{types/interfaces → interfaces}/statement-prepare-options.d.ts +0 -0
- /package/{esm/interfaces → interfaces}/statement-prepare-options.js +0 -0
- /package/{types/protocol → protocol}/backend.d.ts +0 -0
- /package/{types/protocol → protocol}/buffer-reader.d.ts +0 -0
- /package/{types/protocol → protocol}/database-error.d.ts +0 -0
- /package/{types/protocol → protocol}/frontend.d.ts +0 -0
- /package/{types/protocol → protocol}/pg-socket.d.ts +0 -0
- /package/{types/protocol → protocol}/protocol.d.ts +0 -0
- /package/{esm/protocol → protocol}/protocol.js +0 -0
- /package/{types/protocol → protocol}/sasl.d.ts +0 -0
- /package/{esm/protocol → protocol}/sasl.js +0 -0
- /package/{types/protocol → protocol}/smart-buffer.d.ts +0 -0
- /package/{types/safe-event-emitter.d.ts → safe-event-emitter.d.ts} +0 -0
- /package/{esm/safe-event-emitter.js → safe-event-emitter.js} +0 -0
- /package/{types/types.d.ts → types.d.ts} +0 -0
- /package/{esm/types.js → types.js} +0 -0
- /package/{types/util → util}/array-calculatedim.d.ts +0 -0
- /package/{esm/util → util}/array-calculatedim.js +0 -0
- /package/{types/util → util}/bigint-methods.d.ts +0 -0
- /package/{types/util → util}/config-from-env.d.ts +0 -0
- /package/{esm/util → util}/config-from-env.js +0 -0
- /package/{types/util → util}/connection-config.d.ts +0 -0
- /package/{esm/util → util}/connection-config.js +0 -0
- /package/{types/util → util}/convert-row-to-object.d.ts +0 -0
- /package/{esm/util → util}/convert-row-to-object.js +0 -0
- /package/{types/util → util}/decode-binaryarray.d.ts +0 -0
- /package/{esm/util → util}/decode-binaryarray.js +0 -0
- /package/{types/util → util}/encode-binaryarray.d.ts +0 -0
- /package/{esm/util → util}/encode-binaryarray.js +0 -0
- /package/{types/util → util}/escape-literal.d.ts +0 -0
- /package/{esm/util → util}/escape-literal.js +0 -0
- /package/{types/util → util}/fast-parseint.d.ts +0 -0
- /package/{esm/util → util}/fast-parseint.js +0 -0
- /package/{types/util → util}/get-parsers.d.ts +0 -0
- /package/{esm/util → util}/get-parsers.js +0 -0
- /package/{types/util → util}/parse-array.d.ts +0 -0
- /package/{esm/util → util}/parse-array.js +0 -0
- /package/{types/util → util}/parse-datetime.d.ts +0 -0
- /package/{esm/util → util}/parse-datetime.js +0 -0
- /package/{types/util → util}/parse-row.d.ts +0 -0
- /package/{esm/util → util}/parse-row.js +0 -0
- /package/{types/util → util}/parse-time.d.ts +0 -0
- /package/{esm/util → util}/parse-time.js +0 -0
- /package/{types/util → util}/stringify-arrayliteral.d.ts +0 -0
- /package/{esm/util → util}/stringify-arrayliteral.js +0 -0
- /package/{types/util → util}/stringify-for-sql.d.ts +0 -0
- /package/{esm/util → util}/stringify-for-sql.js +0 -0
- /package/{types/util → util}/wrap-row-description.d.ts +0 -0
- /package/{esm/util → util}/wrap-row-description.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
-
### [v2.
|
|
3
|
+
### [v2.23.0](https://github.com/panates/postgrejs/compare/v2.22.9...v2.23.0) -
|
|
4
|
+
|
|
5
|
+
#### 🛠 Refactoring and Updates
|
|
6
|
+
|
|
7
|
+
- dev: Updated deps to support latest TypeScript and NodeJS. @Eray Hanoğlu
|
|
8
|
+
- dev: Updated deps to support latest TypeScript and NodeJS. @Eray Hanoğlu
|
|
9
|
+
|
|
10
|
+
### [v2.22.9](https://github.com/panates/postgrejs/compare/v2.22.8...v2.22.9) - 4 December 2025
|
|
4
11
|
|
|
5
12
|
### [v2.22.8](https://github.com/panates/postgrejs/compare/v2.22.7...v2.22.8) - 27 October 2025
|
|
6
13
|
|
|
@@ -5,10 +5,12 @@ import { BindParam } from './bind-param.js';
|
|
|
5
5
|
import { IntlConnection } from './intl-connection.js';
|
|
6
6
|
import { PreparedStatement } from './prepared-statement.js';
|
|
7
7
|
export class Connection extends SafeEventEmitter {
|
|
8
|
+
_pool;
|
|
9
|
+
_intlCon;
|
|
10
|
+
_notificationListeners = new SafeEventEmitter();
|
|
11
|
+
_closing = false;
|
|
8
12
|
constructor(arg0, arg1) {
|
|
9
13
|
super();
|
|
10
|
-
this._notificationListeners = new SafeEventEmitter();
|
|
11
|
-
this._closing = false;
|
|
12
14
|
if (arg0 &&
|
|
13
15
|
typeof arg0 === 'object' &&
|
|
14
16
|
typeof arg0.acquire === 'function') {
|
|
@@ -4,11 +4,16 @@ import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
|
4
4
|
import { convertRowToObject } from '../util/convert-row-to-object.js';
|
|
5
5
|
import { parseRow } from '../util/parse-row.js';
|
|
6
6
|
export class Cursor extends SafeEventEmitter {
|
|
7
|
+
_statement;
|
|
8
|
+
_portal;
|
|
9
|
+
_parsers;
|
|
10
|
+
_queryOptions;
|
|
11
|
+
_taskQueue = new TaskQueue({ concurrency: 1 });
|
|
12
|
+
_rows = new DoublyLinked();
|
|
13
|
+
_closed = false;
|
|
14
|
+
fields;
|
|
7
15
|
constructor(statement, portal, fields, parsers, queryOptions) {
|
|
8
16
|
super();
|
|
9
|
-
this._taskQueue = new TaskQueue({ concurrency: 1 });
|
|
10
|
-
this._rows = new DoublyLinked();
|
|
11
|
-
this._closed = false;
|
|
12
17
|
this._statement = statement;
|
|
13
18
|
this._portal = portal;
|
|
14
19
|
this._parsers = parsers;
|
|
@@ -13,11 +13,14 @@ import { parseRow } from '../util/parse-row.js';
|
|
|
13
13
|
import { wrapRowDescription } from '../util/wrap-row-description.js';
|
|
14
14
|
const DataFormat = Protocol.DataFormat;
|
|
15
15
|
export class IntlConnection extends SafeEventEmitter {
|
|
16
|
+
_refCount = 0;
|
|
17
|
+
_config;
|
|
18
|
+
_onErrorSavePoint;
|
|
19
|
+
transactionStatus = 'I';
|
|
20
|
+
socket;
|
|
21
|
+
statementQueue = new TaskQueue({ concurrency: 1 });
|
|
16
22
|
constructor(config) {
|
|
17
23
|
super();
|
|
18
|
-
this._refCount = 0;
|
|
19
|
-
this.transactionStatus = 'I';
|
|
20
|
-
this.statementQueue = new TaskQueue({ concurrency: 1 });
|
|
21
24
|
this._config = Object.freeze(getConnectionConfig(config));
|
|
22
25
|
this.socket = new PgSocket(this._config);
|
|
23
26
|
this.socket.on('error', err => this._onError(err));
|
|
@@ -6,9 +6,12 @@ import { getConnectionConfig } from '../util/connection-config.js';
|
|
|
6
6
|
import { Connection } from './connection.js';
|
|
7
7
|
import { getIntlConnection, IntlConnection } from './intl-connection.js';
|
|
8
8
|
export class Pool extends SafeEventEmitter {
|
|
9
|
+
_pool;
|
|
10
|
+
_notificationListeners = new SafeEventEmitter();
|
|
11
|
+
_notificationConnection;
|
|
12
|
+
config;
|
|
9
13
|
constructor(config) {
|
|
10
14
|
super();
|
|
11
|
-
this._notificationListeners = new SafeEventEmitter();
|
|
12
15
|
const cfg = getConnectionConfig(config);
|
|
13
16
|
this.config = Object.freeze(cfg);
|
|
14
17
|
const poolOptions = {};
|
|
@@ -3,8 +3,10 @@ import { GlobalTypeMap } from '../data-type-map.js';
|
|
|
3
3
|
import { Protocol } from '../protocol/protocol.js';
|
|
4
4
|
import { getIntlConnection } from './intl-connection.js';
|
|
5
5
|
export class Portal {
|
|
6
|
+
_statement;
|
|
7
|
+
_name;
|
|
8
|
+
_columnFormat = DEFAULT_COLUMN_FORMAT;
|
|
6
9
|
constructor(statement, name) {
|
|
7
|
-
this._columnFormat = DEFAULT_COLUMN_FORMAT;
|
|
8
10
|
this._statement = statement;
|
|
9
11
|
this._name = name;
|
|
10
12
|
}
|
|
@@ -13,11 +13,14 @@ import { Portal } from './portal.js';
|
|
|
13
13
|
let statementCounter = 0;
|
|
14
14
|
let portalCounter = 0;
|
|
15
15
|
export class PreparedStatement extends SafeEventEmitter {
|
|
16
|
+
_connection;
|
|
17
|
+
_sql = '';
|
|
18
|
+
_name = '';
|
|
19
|
+
_paramTypes;
|
|
20
|
+
_onErrorSavePoint;
|
|
21
|
+
_refCount = 0;
|
|
16
22
|
constructor(connection, sql, paramTypes) {
|
|
17
23
|
super();
|
|
18
|
-
this._sql = '';
|
|
19
|
-
this._name = '';
|
|
20
|
-
this._refCount = 0;
|
|
21
24
|
this._connection = connection;
|
|
22
25
|
this._name = 'S_' + ++statementCounter;
|
|
23
26
|
this._sql = sql;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Protocol } from './protocol/protocol.js';
|
|
2
2
|
var DataFormat = Protocol.DataFormat;
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
Symbol.asyncDispose
|
|
4
|
+
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
|
5
5
|
export { DataFormat };
|
|
6
6
|
export const DEFAULT_COLUMN_FORMAT = DataFormat.binary;
|
|
7
7
|
export var ConnectionState;
|
|
@@ -23,9 +23,9 @@ import { ArrayTimestamptzType, TimestamptzType, } from './data-types/timestamptz
|
|
|
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 {
|
|
26
|
+
_itemsByOID = {};
|
|
27
|
+
_items = [];
|
|
26
28
|
constructor(other) {
|
|
27
|
-
this._itemsByOID = {};
|
|
28
|
-
this._items = [];
|
|
29
29
|
if (other instanceof DataTypeMap)
|
|
30
30
|
Object.assign(this._items, other._items);
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postgrejs",
|
|
3
3
|
"description": "Professional PostgreSQL client NodeJS",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.23.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@jsopen/objects": "^2.0
|
|
8
|
+
"@jsopen/objects": "^2.2.0",
|
|
9
9
|
"doublylinked": "^2.5.6",
|
|
10
10
|
"lightning-pool": "^4.12.0",
|
|
11
11
|
"postgres-bytea": "^3.0.0",
|
|
12
|
-
"power-tasks": "^1.
|
|
12
|
+
"power-tasks": "^1.14.2",
|
|
13
13
|
"putil-promisify": "^1.10.1",
|
|
14
|
-
"putil-varhelpers": "^1.
|
|
14
|
+
"putil-varhelpers": "^1.7.0",
|
|
15
15
|
"tslib": "^2.8.1"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
|
+
"module": "./index.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
18
20
|
"exports": {
|
|
19
21
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"default": "./esm/index.js"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./types/index.d.cts",
|
|
26
|
-
"default": "./cjs/index.js"
|
|
27
|
-
},
|
|
28
|
-
"default": "./esm/index.js"
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"default": "./index.js"
|
|
29
24
|
},
|
|
30
25
|
"./package.json": "./package.json"
|
|
31
26
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20.0"
|
|
29
|
+
},
|
|
35
30
|
"homepage": "https://postgrejs.panates.com/",
|
|
36
31
|
"contributors": [
|
|
37
32
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -40,17 +35,6 @@
|
|
|
40
35
|
"type": "git",
|
|
41
36
|
"url": "https://github.com/panates/postgrejs.git"
|
|
42
37
|
},
|
|
43
|
-
"engines": {
|
|
44
|
-
"node": ">=16.0"
|
|
45
|
-
},
|
|
46
|
-
"files": [
|
|
47
|
-
"cjs/",
|
|
48
|
-
"esm/",
|
|
49
|
-
"types/",
|
|
50
|
-
"LICENSE",
|
|
51
|
-
"README.md",
|
|
52
|
-
"CHANGELOG.md"
|
|
53
|
-
],
|
|
54
38
|
"keywords": [
|
|
55
39
|
"postgresql",
|
|
56
40
|
"postgres",
|
|
@@ -62,10 +46,7 @@
|
|
|
62
46
|
"client",
|
|
63
47
|
"backend",
|
|
64
48
|
"rdbms",
|
|
65
|
-
"sql"
|
|
66
|
-
"typescript",
|
|
67
|
-
"ts",
|
|
68
|
-
"esm"
|
|
49
|
+
"sql"
|
|
69
50
|
],
|
|
70
51
|
"publishConfig": {
|
|
71
52
|
"access": "public"
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
export class DatabaseError extends Error {
|
|
2
|
+
severity;
|
|
3
|
+
code;
|
|
4
|
+
detail;
|
|
5
|
+
hint;
|
|
6
|
+
position;
|
|
7
|
+
internalPosition;
|
|
8
|
+
internalQuery;
|
|
9
|
+
where;
|
|
10
|
+
schema;
|
|
11
|
+
table;
|
|
12
|
+
column;
|
|
13
|
+
dataType;
|
|
14
|
+
constraint;
|
|
15
|
+
lineNr;
|
|
16
|
+
colNr;
|
|
17
|
+
line;
|
|
2
18
|
constructor(msg) {
|
|
3
19
|
super(msg.message);
|
|
4
20
|
Object.assign(this, {
|
|
@@ -13,12 +13,18 @@ import { SASL } from './sasl.js';
|
|
|
13
13
|
const DEFAULT_PORT_NUMBER = 5432;
|
|
14
14
|
const COMMAND_RESULT_PATTERN = /^([^\d]+)(?: (\d+)(?: (\d+))?)?$/;
|
|
15
15
|
export class PgSocket extends SafeEventEmitter {
|
|
16
|
+
options;
|
|
17
|
+
_state = ConnectionState.CLOSED;
|
|
18
|
+
_socket;
|
|
19
|
+
_backend = new Backend();
|
|
20
|
+
_frontend;
|
|
21
|
+
_sessionParameters = {};
|
|
22
|
+
_saslSession;
|
|
23
|
+
_processID;
|
|
24
|
+
_secretKey;
|
|
16
25
|
constructor(options) {
|
|
17
26
|
super();
|
|
18
27
|
this.options = options;
|
|
19
|
-
this._state = ConnectionState.CLOSED;
|
|
20
|
-
this._backend = new Backend();
|
|
21
|
-
this._sessionParameters = {};
|
|
22
28
|
this._frontend = new Frontend({ buffer: options.buffer });
|
|
23
29
|
this.setMaxListeners(99);
|
|
24
30
|
}
|
|
@@ -2,11 +2,17 @@ import * as os from 'os';
|
|
|
2
2
|
import { writeBigUInt64BE } from '../util/bigint-methods.js';
|
|
3
3
|
import { BufferReader } from './buffer-reader.js';
|
|
4
4
|
export class SmartBuffer extends BufferReader {
|
|
5
|
+
static DEFAULT_PAGE_SIZE = 4096;
|
|
6
|
+
static DEFAULT_MAX_SIZE = Math.min(Math.floor(os.totalmem() / 2), 1024 * 1024 * 1024 * 2);
|
|
7
|
+
_houseKeepInterval;
|
|
8
|
+
_houseKeepTimer;
|
|
9
|
+
_lastHouseKeep = 0;
|
|
10
|
+
_stMaxPages = 1;
|
|
11
|
+
_length = 0;
|
|
12
|
+
pageSize;
|
|
13
|
+
maxSize;
|
|
5
14
|
constructor(cfg) {
|
|
6
15
|
super(Buffer.allocUnsafe(cfg?.pageSize || SmartBuffer.DEFAULT_PAGE_SIZE));
|
|
7
|
-
this._lastHouseKeep = 0;
|
|
8
|
-
this._stMaxPages = 1;
|
|
9
|
-
this._length = 0;
|
|
10
16
|
this._houseKeepInterval = cfg?.houseKeepInterval || 5000;
|
|
11
17
|
this.pageSize = this.buffer.length;
|
|
12
18
|
this.maxSize = cfg?.maxLength || SmartBuffer.DEFAULT_MAX_SIZE;
|
|
@@ -169,5 +175,3 @@ export class SmartBuffer extends BufferReader {
|
|
|
169
175
|
this._stMaxPages = this.length ? Math.ceil(this.length / this.pageSize) : 1;
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
|
-
SmartBuffer.DEFAULT_PAGE_SIZE = 4096;
|
|
173
|
-
SmartBuffer.DEFAULT_MAX_SIZE = Math.min(Math.floor(os.totalmem() / 2), 1024 * 1024 * 1024 * 2);
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Connection = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
const data_type_map_js_1 = require("../data-type-map.js");
|
|
6
|
-
const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
|
|
7
|
-
const bind_param_js_1 = require("./bind-param.js");
|
|
8
|
-
const intl_connection_js_1 = require("./intl-connection.js");
|
|
9
|
-
const prepared_statement_js_1 = require("./prepared-statement.js");
|
|
10
|
-
class Connection extends safe_event_emitter_js_1.SafeEventEmitter {
|
|
11
|
-
constructor(arg0, arg1) {
|
|
12
|
-
super();
|
|
13
|
-
this._notificationListeners = new safe_event_emitter_js_1.SafeEventEmitter();
|
|
14
|
-
this._closing = false;
|
|
15
|
-
if (arg0 &&
|
|
16
|
-
typeof arg0 === 'object' &&
|
|
17
|
-
typeof arg0.acquire === 'function') {
|
|
18
|
-
if (!(arg1 instanceof intl_connection_js_1.IntlConnection))
|
|
19
|
-
throw new TypeError('Invalid argument');
|
|
20
|
-
this._pool = arg0;
|
|
21
|
-
this._intlCon = arg1;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
this._intlCon = new intl_connection_js_1.IntlConnection(arg0);
|
|
25
|
-
}
|
|
26
|
-
this._intlCon.on('ready', (...args) => this.emit('ready', ...args));
|
|
27
|
-
this._intlCon.on('error', (...args) => this.emit('error', ...args));
|
|
28
|
-
this._intlCon.on('close', (...args) => this.emit('close', ...args));
|
|
29
|
-
this._intlCon.on('connecting', (...args) => this.emit('connecting', ...args));
|
|
30
|
-
this._intlCon.on('ready', (...args) => this.emit('ready', ...args));
|
|
31
|
-
this._intlCon.on('terminate', (...args) => this.emit('terminate', ...args));
|
|
32
|
-
this._intlCon.on('notification', (msg) => this._handleNotification(msg));
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns configuration object
|
|
36
|
-
*/
|
|
37
|
-
get config() {
|
|
38
|
-
return this._intlCon.config;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Returns true if connection is in a transaction
|
|
42
|
-
*/
|
|
43
|
-
get inTransaction() {
|
|
44
|
-
return this._intlCon.inTransaction;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Returns current state of the connection
|
|
48
|
-
*/
|
|
49
|
-
get state() {
|
|
50
|
-
return this._intlCon.state;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns processId of current session
|
|
54
|
-
*/
|
|
55
|
-
get processID() {
|
|
56
|
-
return this._intlCon.processID;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns information parameters for current session
|
|
60
|
-
*/
|
|
61
|
-
get sessionParameters() {
|
|
62
|
-
return this._intlCon.sessionParameters;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns secret key of current session
|
|
66
|
-
*/
|
|
67
|
-
get secretKey() {
|
|
68
|
-
return this._intlCon.secretKey;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Connects to the server
|
|
72
|
-
*/
|
|
73
|
-
async connect() {
|
|
74
|
-
await this._captureErrorStack(this._intlCon.connect());
|
|
75
|
-
if (this.state === constants_js_1.ConnectionState.READY)
|
|
76
|
-
this._closing = false;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Closes connection. You can define how long time the connection will
|
|
80
|
-
* wait for active queries before terminating the connection.
|
|
81
|
-
* On the end of the given time, it forces to close the socket and than emits `terminate` event.
|
|
82
|
-
*
|
|
83
|
-
* @param terminateWait {number} - Determines how long the connection will wait for active queries before terminating.
|
|
84
|
-
*/
|
|
85
|
-
async close(terminateWait) {
|
|
86
|
-
this._notificationListeners.removeAllListeners();
|
|
87
|
-
this._intlCon.statementQueue.clearQueue();
|
|
88
|
-
if (this.state === constants_js_1.ConnectionState.CLOSED || this._closing)
|
|
89
|
-
return;
|
|
90
|
-
/* istanbul ignore next */
|
|
91
|
-
if (this.listenerCount('debug')) {
|
|
92
|
-
this.emit('debug', {
|
|
93
|
-
location: 'Connection.close',
|
|
94
|
-
connection: this,
|
|
95
|
-
message: `[${this.processID}] closing`,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
this._closing = true;
|
|
99
|
-
if (this._intlCon.refCount > 0 &&
|
|
100
|
-
typeof terminateWait === 'number' &&
|
|
101
|
-
terminateWait > 0) {
|
|
102
|
-
const startTime = Date.now();
|
|
103
|
-
return this._captureErrorStack(new Promise((resolve, reject) => {
|
|
104
|
-
/* istanbul ignore next */
|
|
105
|
-
if (this.listenerCount('debug')) {
|
|
106
|
-
this.emit('debug', {
|
|
107
|
-
location: 'Connection.close',
|
|
108
|
-
connection: this,
|
|
109
|
-
message: `[${this.processID}] waiting active queries`,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const timer = setInterval(() => {
|
|
113
|
-
if (this._intlCon.refCount <= 0 ||
|
|
114
|
-
Date.now() > startTime + terminateWait) {
|
|
115
|
-
clearInterval(timer);
|
|
116
|
-
if (this._intlCon.refCount > 0) {
|
|
117
|
-
/* istanbul ignore next */
|
|
118
|
-
if (this.listenerCount('debug')) {
|
|
119
|
-
this.emit('debug', {
|
|
120
|
-
location: 'Connection.close',
|
|
121
|
-
connection: this,
|
|
122
|
-
message: `[${this.processID}] terminate`,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
this.emit('terminate');
|
|
126
|
-
}
|
|
127
|
-
this._close().then(resolve).catch(reject);
|
|
128
|
-
}
|
|
129
|
-
}, 50);
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
await this._close();
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Executes single or multiple SQL scripts using Simple Query protocol.
|
|
136
|
-
*
|
|
137
|
-
* @param sql {string} - SQL script that will be executed
|
|
138
|
-
* @param options {ScriptExecuteOptions} - Execute options
|
|
139
|
-
*/
|
|
140
|
-
async execute(sql, options) {
|
|
141
|
-
this.emit('execute', sql, options);
|
|
142
|
-
return this._captureErrorStack(this._intlCon.execute(sql, options)).catch((e) => {
|
|
143
|
-
throw this._handleError(e, sql);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
async query(sql, options) {
|
|
147
|
-
this._intlCon.assertConnected();
|
|
148
|
-
/* istanbul ignore next */
|
|
149
|
-
if (this.listenerCount('debug')) {
|
|
150
|
-
this.emit('debug', {
|
|
151
|
-
location: 'Connection.query',
|
|
152
|
-
connection: this,
|
|
153
|
-
message: `[${this.processID}] query | ${sql}`,
|
|
154
|
-
sql,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
this.emit('query', sql, options);
|
|
158
|
-
const typeMap = options?.typeMap || data_type_map_js_1.GlobalTypeMap;
|
|
159
|
-
const paramTypes = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.oid : typeMap.determine(prm));
|
|
160
|
-
const statement = await this.prepare(sql, { paramTypes, typeMap }).catch((e) => {
|
|
161
|
-
throw this._handleError(e, sql);
|
|
162
|
-
});
|
|
163
|
-
try {
|
|
164
|
-
const params = options?.params?.map(prm => prm instanceof bind_param_js_1.BindParam ? prm.value : prm);
|
|
165
|
-
return await this._captureErrorStack(statement.execute({ ...options, params }));
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
await statement.close();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Creates a PreparedStatement instance
|
|
173
|
-
* @param sql {string} - SQL script that will be executed
|
|
174
|
-
* @param options {StatementPrepareOptions} - Options
|
|
175
|
-
*/
|
|
176
|
-
async prepare(sql, options) {
|
|
177
|
-
/* istanbul ignore next */
|
|
178
|
-
if (this.listenerCount('debug')) {
|
|
179
|
-
this.emit('debug', {
|
|
180
|
-
location: 'Connection.prepare',
|
|
181
|
-
connection: this,
|
|
182
|
-
message: `[${this.processID}] prepare | ${sql}`,
|
|
183
|
-
sql,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
return await this._captureErrorStack(prepared_statement_js_1.PreparedStatement.prepare(this, sql, options));
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Starts a transaction
|
|
190
|
-
*/
|
|
191
|
-
startTransaction() {
|
|
192
|
-
return this._captureErrorStack(this._intlCon.startTransaction());
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Commits current transaction
|
|
196
|
-
*/
|
|
197
|
-
commit() {
|
|
198
|
-
return this._captureErrorStack(this._intlCon.commit());
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Rolls back current transaction
|
|
202
|
-
*/
|
|
203
|
-
rollback() {
|
|
204
|
-
return this._captureErrorStack(this._intlCon.rollback());
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Starts transaction and creates a savepoint
|
|
208
|
-
* @param name {string} - Name of the savepoint
|
|
209
|
-
*/
|
|
210
|
-
async savepoint(name) {
|
|
211
|
-
if (!this._intlCon.inTransaction)
|
|
212
|
-
await this._intlCon.startTransaction();
|
|
213
|
-
return this._captureErrorStack(this._intlCon.savepoint(name));
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Rolls back current transaction to given savepoint
|
|
217
|
-
* @param name {string} - Name of the savepoint
|
|
218
|
-
*/
|
|
219
|
-
rollbackToSavepoint(name) {
|
|
220
|
-
return this._captureErrorStack(this._intlCon.rollbackToSavepoint(name));
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Releases savepoint
|
|
224
|
-
* @param name {string} - Name of the savepoint
|
|
225
|
-
*/
|
|
226
|
-
releaseSavepoint(name) {
|
|
227
|
-
return this._captureErrorStack(this._intlCon.releaseSavepoint(name));
|
|
228
|
-
}
|
|
229
|
-
async listen(channel, callback) {
|
|
230
|
-
if (!/^[A-Z]\w+$/i.test(channel))
|
|
231
|
-
throw new TypeError(`Invalid channel name`);
|
|
232
|
-
const registered = !!this._notificationListeners.eventNames().length;
|
|
233
|
-
this._notificationListeners.on(channel, callback);
|
|
234
|
-
if (!registered)
|
|
235
|
-
await this._captureErrorStack(this.query('LISTEN ' + channel));
|
|
236
|
-
}
|
|
237
|
-
async unListen(channel) {
|
|
238
|
-
if (!/^[A-Z]\w+$/i.test(channel))
|
|
239
|
-
throw new TypeError(`Invalid channel name`);
|
|
240
|
-
this._notificationListeners.removeAllListeners(channel);
|
|
241
|
-
await this._captureErrorStack(this.query('UNLISTEN ' + channel));
|
|
242
|
-
}
|
|
243
|
-
async unListenAll() {
|
|
244
|
-
this._notificationListeners.removeAllListeners();
|
|
245
|
-
await this._captureErrorStack(this.query('UNLISTEN *'));
|
|
246
|
-
}
|
|
247
|
-
_handleNotification(msg) {
|
|
248
|
-
this.emit('notification', msg);
|
|
249
|
-
this._notificationListeners.emit(msg.channel, msg);
|
|
250
|
-
}
|
|
251
|
-
async _close() {
|
|
252
|
-
if (this._pool) {
|
|
253
|
-
await this._captureErrorStack(this._pool.release(this));
|
|
254
|
-
this.emit('release');
|
|
255
|
-
}
|
|
256
|
-
else
|
|
257
|
-
await this._captureErrorStack(this._intlCon.close());
|
|
258
|
-
this._closing = false;
|
|
259
|
-
}
|
|
260
|
-
_handleError(err, script) {
|
|
261
|
-
if (err.position != null) {
|
|
262
|
-
const i1 = script.lastIndexOf('\n', err.position - 1) + 1;
|
|
263
|
-
err.lineNr = [...script.substring(0, i1).matchAll(/\n/g)].length + 1;
|
|
264
|
-
err.colNr = err.position - i1;
|
|
265
|
-
const lines = script.split('\n');
|
|
266
|
-
err.line = lines[err.lineNr - 1];
|
|
267
|
-
err.message += `\n at line ${err.lineNr} column ${err.colNr}`;
|
|
268
|
-
if (err.lineNr > 1)
|
|
269
|
-
err.message += `\n${String(err.lineNr - 1).padStart(3)}| ${lines[err.lineNr - 2]}`;
|
|
270
|
-
err.message += `\n${String(err.lineNr).padStart(3)}| ${err.line}\n .${'-'.repeat(Math.max(err.colNr - 1, 0))}^`;
|
|
271
|
-
}
|
|
272
|
-
return err;
|
|
273
|
-
}
|
|
274
|
-
async _captureErrorStack(promise) {
|
|
275
|
-
const stack = new Error().stack;
|
|
276
|
-
return promise.catch(e => {
|
|
277
|
-
if (e instanceof Error && stack) {
|
|
278
|
-
if (e.stack && stack) {
|
|
279
|
-
e.stack =
|
|
280
|
-
e.stack.substring(0, e.stack.indexOf('\n')) +
|
|
281
|
-
'\n' +
|
|
282
|
-
stack
|
|
283
|
-
.split('\n')
|
|
284
|
-
.filter((x, i) => i && !x.includes('._captureErrorStack'))
|
|
285
|
-
.join('\n');
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
throw e;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
[Symbol.asyncDispose]() {
|
|
292
|
-
return this.close();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
exports.Connection = Connection;
|