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,12 @@
|
|
|
1
|
+
import type { DataType } from '../interfaces/data-type.js';
|
|
2
|
+
export declare const NumericType: DataType;
|
|
3
|
+
export declare const ArrayNumericType: DataType;
|
|
4
|
+
/**
|
|
5
|
+
* Convert a number from binary representation to text representation.
|
|
6
|
+
* @param digits array of shorts that can be decoded as the number String
|
|
7
|
+
* @param scale the scale of the number binary representation
|
|
8
|
+
* @param weight the weight of the number binary representation
|
|
9
|
+
* @param sign the sign of the number
|
|
10
|
+
* @return String the number as String
|
|
11
|
+
*/
|
|
12
|
+
export declare function numberBytesToString(digits: number[], scale: number, weight: number, sign: number): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './data-type-map.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './connection/bind-param.js';
|
|
5
|
+
export * from './connection/connection.js';
|
|
6
|
+
export * from './connection/cursor.js';
|
|
7
|
+
export * from './connection/pool.js';
|
|
8
|
+
export * from './connection/prepared-statement.js';
|
|
9
|
+
export * from './interfaces/command-result.js';
|
|
10
|
+
export * from './interfaces/data-mapping-options.js';
|
|
11
|
+
export * from './interfaces/data-type.js';
|
|
12
|
+
export * from './interfaces/database-connection-params.js';
|
|
13
|
+
export * from './interfaces/field-info.js';
|
|
14
|
+
export * from './interfaces/query-options.js';
|
|
15
|
+
export * from './interfaces/query-result.js';
|
|
16
|
+
export * from './interfaces/script-execute-options.js';
|
|
17
|
+
export * from './interfaces/script-result.js';
|
|
18
|
+
export * from './interfaces/statement-prepare-options.js';
|
|
19
|
+
export * from './util/connection-config.js';
|
|
20
|
+
export * from './util/escape-literal.js';
|
|
21
|
+
export * from './util/parse-datetime.js';
|
|
22
|
+
export * from './util/stringify-arrayliteral.js';
|
|
23
|
+
export * from './util/stringify-for-sql.js';
|
|
24
|
+
export * from './protocol/smart-buffer.js';
|
|
25
|
+
export * from './protocol/database-error.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Row } from '../types.js';
|
|
2
|
+
import type { FieldInfo } from './field-info.js';
|
|
3
|
+
export interface CommandResult {
|
|
4
|
+
/**
|
|
5
|
+
* Name of the command (INSERT, SELECT, UPDATE, etc.)
|
|
6
|
+
*/
|
|
7
|
+
command?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Contains information about fields in column order
|
|
10
|
+
*/
|
|
11
|
+
fields?: FieldInfo[];
|
|
12
|
+
/**
|
|
13
|
+
* Contains array of row data
|
|
14
|
+
*/
|
|
15
|
+
rows?: Row[];
|
|
16
|
+
/**
|
|
17
|
+
* Contains row type
|
|
18
|
+
*/
|
|
19
|
+
rowType?: 'array' | 'object';
|
|
20
|
+
/**
|
|
21
|
+
* Time elapsed to execute command
|
|
22
|
+
*/
|
|
23
|
+
executeTime?: number;
|
|
24
|
+
/**
|
|
25
|
+
* How many rows affected
|
|
26
|
+
*/
|
|
27
|
+
rowsAffected?: number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DecodeBinaryFunction, EncodeBinaryFunction, EncodeTextFunction, OID, ParseTextFunction } from '../types.js';
|
|
2
|
+
import { EncodeCalculateDimFunction } from '../types.js';
|
|
3
|
+
export interface DataType {
|
|
4
|
+
oid: OID;
|
|
5
|
+
name: string;
|
|
6
|
+
elementsOID?: OID;
|
|
7
|
+
isArray?: boolean;
|
|
8
|
+
jsType: string;
|
|
9
|
+
arraySeparator?: string;
|
|
10
|
+
isType: (v: any) => boolean;
|
|
11
|
+
parseBinary: DecodeBinaryFunction;
|
|
12
|
+
parseText: ParseTextFunction;
|
|
13
|
+
encodeBinary?: EncodeBinaryFunction;
|
|
14
|
+
encodeText?: EncodeTextFunction;
|
|
15
|
+
encodeCalculateDim?: EncodeCalculateDimFunction;
|
|
16
|
+
}
|
|
17
|
+
export interface Point {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}
|
|
21
|
+
export interface Circle {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
r: number;
|
|
25
|
+
}
|
|
26
|
+
export interface Rectangle {
|
|
27
|
+
x1: number;
|
|
28
|
+
y1: number;
|
|
29
|
+
x2: number;
|
|
30
|
+
y2: number;
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { PoolConfiguration as LPoolConfiguration } from 'lightning-pool';
|
|
3
|
+
import type { ConnectionOptions as TlsConnectionOptions } from 'tls';
|
|
4
|
+
import type { SmartBufferConfig } from '../protocol/smart-buffer.js';
|
|
5
|
+
import type { DebugLogger } from '../types.js';
|
|
6
|
+
export interface DatabaseConnectionParams {
|
|
7
|
+
host?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
user?: string;
|
|
10
|
+
password?: string | (() => string | Promise<string>);
|
|
11
|
+
database?: string;
|
|
12
|
+
applicationName?: string;
|
|
13
|
+
ssl?: TlsConnectionOptions;
|
|
14
|
+
timezone?: string;
|
|
15
|
+
schema?: string;
|
|
16
|
+
connectTimeoutMs?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Specifies weather execute query in auto-commit mode
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
autoCommit?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* When on, if a statement in a transaction block generates an error,
|
|
24
|
+
* the error is ignored and the transaction continues.
|
|
25
|
+
* When off (the default), a statement in a transaction block that generates an error aborts the entire transaction
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
rollbackOnError?: boolean;
|
|
29
|
+
debugLogger?: DebugLogger;
|
|
30
|
+
}
|
|
31
|
+
export interface SocketOptions {
|
|
32
|
+
keepAlive?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ConnectionConfiguration extends DatabaseConnectionParams, SocketOptions {
|
|
35
|
+
buffer?: SmartBufferConfig;
|
|
36
|
+
}
|
|
37
|
+
export interface PoolConfiguration extends ConnectionConfiguration, LPoolConfiguration {
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface FieldInfo {
|
|
2
|
+
/**
|
|
3
|
+
* Name of the field
|
|
4
|
+
*/
|
|
5
|
+
fieldName: string;
|
|
6
|
+
/**
|
|
7
|
+
* OID of the table
|
|
8
|
+
*/
|
|
9
|
+
tableId?: number;
|
|
10
|
+
/**
|
|
11
|
+
* OID of the column
|
|
12
|
+
*/
|
|
13
|
+
columnId?: number;
|
|
14
|
+
/**
|
|
15
|
+
* OID of the data type
|
|
16
|
+
*/
|
|
17
|
+
dataTypeId: number;
|
|
18
|
+
/**
|
|
19
|
+
* Name of the data type
|
|
20
|
+
*/
|
|
21
|
+
dataTypeName: string;
|
|
22
|
+
/**
|
|
23
|
+
* OID of the elements data type if field is an array
|
|
24
|
+
*/
|
|
25
|
+
elementDataTypeId?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the elements data type if field is an array
|
|
28
|
+
*/
|
|
29
|
+
elementDataTypeName?: string;
|
|
30
|
+
/**
|
|
31
|
+
* JS type name that data type mapped
|
|
32
|
+
*/
|
|
33
|
+
jsType: string;
|
|
34
|
+
/**
|
|
35
|
+
* Data length if data type has a fixed size
|
|
36
|
+
*/
|
|
37
|
+
fixedSize?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Modifier of the data type
|
|
40
|
+
*/
|
|
41
|
+
modifier?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the data type is an array
|
|
44
|
+
*/
|
|
45
|
+
isArray?: boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BindParam } from '../connection/bind-param';
|
|
2
|
+
import type { DataFormat } from '../constants.js';
|
|
3
|
+
import type { DataTypeMap } from '../data-type-map';
|
|
4
|
+
import type { DataMappingOptions } from './data-mapping-options.js';
|
|
5
|
+
export interface QueryOptions extends DataMappingOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Specifies weather execute query in auto-commit mode
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
autoCommit?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Specifies if rows will be fetched as <FieldName, Value> pair objects or array of values
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
objectRows?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Data type map instance
|
|
18
|
+
* @default GlobalTypeMap
|
|
19
|
+
*/
|
|
20
|
+
typeMap?: DataTypeMap;
|
|
21
|
+
/**
|
|
22
|
+
* If true, returns Cursor instance instead of rows
|
|
23
|
+
*/
|
|
24
|
+
cursor?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Query execution parameters
|
|
27
|
+
*/
|
|
28
|
+
params?: (BindParam | any)[];
|
|
29
|
+
/**
|
|
30
|
+
* Specifies transfer format (binary or text) for each column
|
|
31
|
+
* @default DataFormat.binary
|
|
32
|
+
*/
|
|
33
|
+
columnFormat?: DataFormat | DataFormat[];
|
|
34
|
+
/**
|
|
35
|
+
* Specifies how many rows will be fetched. For Cursor, this value specifies how many rows will be fetched in a batch
|
|
36
|
+
* @default 100
|
|
37
|
+
*/
|
|
38
|
+
fetchCount?: number;
|
|
39
|
+
/**
|
|
40
|
+
* When on, if a statement in a transaction block generates an error,
|
|
41
|
+
* the error is ignored and the transaction continues.
|
|
42
|
+
* When off (the default), a statement in a transaction block that generates an error aborts the entire transaction
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
rollbackOnError?: boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DataTypeMap } from '../data-type-map';
|
|
2
|
+
import type { DataMappingOptions } from './data-mapping-options.js';
|
|
3
|
+
export interface ScriptExecuteOptions extends DataMappingOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Specifies weather execute query in auto-commit mode
|
|
6
|
+
* @default true
|
|
7
|
+
*/
|
|
8
|
+
autoCommit?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Specifies if rows will be fetched as <FieldName, Value> pair objects or array of values
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
objectRows?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Data type map instance
|
|
16
|
+
* @default GlobalTypeMap
|
|
17
|
+
*/
|
|
18
|
+
typeMap?: DataTypeMap;
|
|
19
|
+
/**
|
|
20
|
+
* When on, if a statement in a transaction block generates an error,
|
|
21
|
+
* the error is ignored and the transaction continues.
|
|
22
|
+
* When off (the default), a statement in a transaction block that generates an error aborts the entire transaction
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
rollbackOnError?: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CommandResult } from './command-result.js';
|
|
2
|
+
export interface ScriptResult {
|
|
3
|
+
/**
|
|
4
|
+
* Array of command result for each sql command in the script
|
|
5
|
+
*/
|
|
6
|
+
results: CommandResult[];
|
|
7
|
+
/**
|
|
8
|
+
* Command count in the script
|
|
9
|
+
*/
|
|
10
|
+
totalCommands: number;
|
|
11
|
+
/**
|
|
12
|
+
* Total execution time
|
|
13
|
+
*/
|
|
14
|
+
totalTime: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DataTypeMap } from '../data-type-map';
|
|
2
|
+
import type { OID } from '../types.js';
|
|
3
|
+
export interface StatementPrepareOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Specifies data type for each parameter
|
|
6
|
+
*/
|
|
7
|
+
paramTypes?: OID[];
|
|
8
|
+
/**
|
|
9
|
+
* Data type map instance
|
|
10
|
+
* @default GlobalTypeMap
|
|
11
|
+
*/
|
|
12
|
+
typeMap?: DataTypeMap;
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Protocol } from './protocol.js';
|
|
3
|
+
declare type ParseCallback = (code: Protocol.BackendMessageCode, data?: any) => void;
|
|
4
|
+
export declare class Backend {
|
|
5
|
+
private _buf?;
|
|
6
|
+
reset(): void;
|
|
7
|
+
parse(data: Buffer, callback: ParseCallback): void;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class BufferReader {
|
|
3
|
+
buffer: Buffer;
|
|
4
|
+
offset: number;
|
|
5
|
+
constructor(buffer: Buffer);
|
|
6
|
+
get length(): number;
|
|
7
|
+
readUInt8(): number;
|
|
8
|
+
readUInt16BE(): number;
|
|
9
|
+
readInt16BE(): number;
|
|
10
|
+
readUInt32BE(): number;
|
|
11
|
+
readInt32BE(): number;
|
|
12
|
+
readCString(encoding?: BufferEncoding): string;
|
|
13
|
+
readLString(len: number, encoding?: BufferEncoding): string | null;
|
|
14
|
+
readBuffer(len?: number): Buffer;
|
|
15
|
+
moveBy(n: number): this;
|
|
16
|
+
moveTo(pos: number): this;
|
|
17
|
+
private _checkReadable;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Protocol } from './protocol.js';
|
|
2
|
+
export declare class DatabaseError extends Error {
|
|
3
|
+
severity?: string;
|
|
4
|
+
code?: string;
|
|
5
|
+
detail?: string;
|
|
6
|
+
hint?: string;
|
|
7
|
+
position?: number;
|
|
8
|
+
internalPosition?: string;
|
|
9
|
+
internalQuery?: string;
|
|
10
|
+
where?: string;
|
|
11
|
+
schema?: string;
|
|
12
|
+
table?: string;
|
|
13
|
+
column?: string;
|
|
14
|
+
dataType?: string;
|
|
15
|
+
constraint?: string;
|
|
16
|
+
lineNr?: number;
|
|
17
|
+
colNr?: number;
|
|
18
|
+
line?: string;
|
|
19
|
+
constructor(msg: Protocol.ErrorResponseMessage);
|
|
20
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DataTypeMap } from '../data-type-map.js';
|
|
3
|
+
import { QueryOptions } from '../interfaces/query-options.js';
|
|
4
|
+
import { Maybe, OID } from '../types.js';
|
|
5
|
+
import { SASL } from './sasl.js';
|
|
6
|
+
import { SmartBufferConfig } from './smart-buffer.js';
|
|
7
|
+
export interface FrontendOptions {
|
|
8
|
+
buffer?: SmartBufferConfig;
|
|
9
|
+
}
|
|
10
|
+
export declare namespace Frontend {
|
|
11
|
+
interface StartupMessageArgs {
|
|
12
|
+
user: string;
|
|
13
|
+
database: string;
|
|
14
|
+
[index: string]: string;
|
|
15
|
+
}
|
|
16
|
+
interface BindMessageArgs {
|
|
17
|
+
typeMap: DataTypeMap;
|
|
18
|
+
statement?: string;
|
|
19
|
+
portal?: string;
|
|
20
|
+
paramTypes?: Maybe<OID>[];
|
|
21
|
+
params?: any[];
|
|
22
|
+
queryOptions: QueryOptions;
|
|
23
|
+
}
|
|
24
|
+
interface ParseMessageArgs {
|
|
25
|
+
statement?: string;
|
|
26
|
+
sql: string;
|
|
27
|
+
paramTypes?: Maybe<OID>[];
|
|
28
|
+
}
|
|
29
|
+
interface DescribeMessageArgs {
|
|
30
|
+
type: 'P' | 'S';
|
|
31
|
+
name?: string;
|
|
32
|
+
}
|
|
33
|
+
interface ExecuteMessageArgs {
|
|
34
|
+
portal?: string;
|
|
35
|
+
fetchCount?: number;
|
|
36
|
+
}
|
|
37
|
+
interface CloseMessageArgs {
|
|
38
|
+
type: 'P' | 'S';
|
|
39
|
+
name?: string;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export declare class Frontend {
|
|
43
|
+
private _io;
|
|
44
|
+
constructor(options?: FrontendOptions);
|
|
45
|
+
getSSLRequestMessage(): Buffer;
|
|
46
|
+
getStartupMessage(args: Frontend.StartupMessageArgs): Buffer;
|
|
47
|
+
getPasswordMessage(password: string): Buffer;
|
|
48
|
+
getSASLMessage(sasl: SASL.Session): Buffer;
|
|
49
|
+
getSASLFinalMessage(session: SASL.Session): Buffer;
|
|
50
|
+
getParseMessage(args: Frontend.ParseMessageArgs): Buffer;
|
|
51
|
+
getBindMessage(args: Frontend.BindMessageArgs): Buffer;
|
|
52
|
+
getDescribeMessage(args: Frontend.DescribeMessageArgs): Buffer;
|
|
53
|
+
getExecuteMessage(args: Frontend.ExecuteMessageArgs): Buffer;
|
|
54
|
+
getCloseMessage(args: Frontend.CloseMessageArgs): Buffer;
|
|
55
|
+
getQueryMessage(sql: string): Buffer;
|
|
56
|
+
getFlushMessage(): Buffer;
|
|
57
|
+
getTerminateMessage(): Buffer;
|
|
58
|
+
getSyncMessage(): Buffer;
|
|
59
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ConnectionState } from '../constants.js';
|
|
3
|
+
import { ConnectionConfiguration } from '../interfaces/database-connection-params.js';
|
|
4
|
+
import { SafeEventEmitter } from '../safe-event-emitter.js';
|
|
5
|
+
import { Callback, Maybe } from '../types.js';
|
|
6
|
+
import { Frontend } from './frontend.js';
|
|
7
|
+
import { Protocol } from './protocol.js';
|
|
8
|
+
export type CaptureCallback = (code: Protocol.BackendMessageCode, msg: any, done: (err: Maybe<Error>, result?: any) => void) => void | Promise<void>;
|
|
9
|
+
export interface SocketError extends Error {
|
|
10
|
+
code: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class PgSocket extends SafeEventEmitter {
|
|
13
|
+
options: ConnectionConfiguration;
|
|
14
|
+
private _state;
|
|
15
|
+
private _socket?;
|
|
16
|
+
private _backend;
|
|
17
|
+
private _frontend;
|
|
18
|
+
private _sessionParameters;
|
|
19
|
+
private _saslSession?;
|
|
20
|
+
private _processID?;
|
|
21
|
+
private _secretKey?;
|
|
22
|
+
constructor(options: ConnectionConfiguration);
|
|
23
|
+
get state(): ConnectionState;
|
|
24
|
+
get processID(): Maybe<number>;
|
|
25
|
+
get secretKey(): Maybe<number>;
|
|
26
|
+
get sessionParameters(): Record<string, string>;
|
|
27
|
+
connect(): void;
|
|
28
|
+
close(): void;
|
|
29
|
+
sendParseMessage(args: Frontend.ParseMessageArgs, cb?: Callback): void;
|
|
30
|
+
sendBindMessage(args: Frontend.BindMessageArgs, cb?: Callback): void;
|
|
31
|
+
sendDescribeMessage(args: Frontend.DescribeMessageArgs, cb?: Callback): void;
|
|
32
|
+
sendExecuteMessage(args: Frontend.ExecuteMessageArgs, cb?: Callback): void;
|
|
33
|
+
sendCloseMessage(args: Frontend.CloseMessageArgs, cb?: Callback): void;
|
|
34
|
+
sendQueryMessage(sql: string, cb?: Callback): void;
|
|
35
|
+
sendFlushMessage(cb?: Callback): void;
|
|
36
|
+
sendTerminateMessage(cb?: Callback): void;
|
|
37
|
+
sendSyncMessage(): void;
|
|
38
|
+
capture(callback: CaptureCallback): Promise<any>;
|
|
39
|
+
protected _removeListeners(): void;
|
|
40
|
+
protected _reset(): void;
|
|
41
|
+
protected _handleConnect(): void;
|
|
42
|
+
protected _handleClose(): void;
|
|
43
|
+
protected _handleError(err: unknown): void;
|
|
44
|
+
protected _handleData(data: Buffer): void;
|
|
45
|
+
protected _resolvePassword(cb: (password: string) => void): void;
|
|
46
|
+
protected _handleAuthenticationMessage(msg?: any): void;
|
|
47
|
+
protected _handleParameterStatus(msg: Protocol.ParameterStatusMessage): void;
|
|
48
|
+
protected _handleBackendKeyData(msg: Protocol.BackendKeyDataMessage): void;
|
|
49
|
+
protected _handleCommandComplete(msg: any): Protocol.CommandCompleteMessage;
|
|
50
|
+
protected _send(data: Buffer, cb?: Callback): void;
|
|
51
|
+
}
|