postgrejs 3.8.0 → 3.9.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 +38 -1
- package/README.md +50 -0
- package/connection/connection.d.ts +14 -2
- package/connection/connection.js +57 -9
- package/connection/intl-connection.d.ts +146 -5
- package/connection/intl-connection.js +458 -30
- package/connection/pool.d.ts +30 -6
- package/connection/pool.js +22 -3
- package/connection/prepared-statement.js +22 -2
- package/data-type-map.d.ts +16 -0
- package/data-type-map.js +56 -12
- package/data-types/date-type.js +2 -2
- package/data-types/money-type.d.ts +38 -0
- package/data-types/money-type.js +203 -0
- package/data-types/numeric-type.d.ts +2 -0
- package/data-types/numeric-type.js +1 -1
- package/data-types/timestamp-type.js +2 -2
- package/data-types/timestamptz-type.js +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/interfaces/data-mapping-options.d.ts +27 -0
- package/interfaces/database-connection-params.d.ts +32 -5
- package/interfaces/query-options.d.ts +32 -0
- package/interfaces/script-execute-options.d.ts +32 -0
- package/interfaces/transaction-options.d.ts +27 -0
- package/interfaces/transaction-options.js +1 -0
- package/package.json +1 -1
- package/protocol/database-error.d.ts +15 -0
- package/protocol/database-error.js +19 -0
- package/protocol/frontend.js +1 -1
- package/protocol/pg-socket.js +7 -10
- package/util/array-leaf.d.ts +10 -0
- package/util/array-leaf.js +22 -0
- package/util/date-style.d.ts +47 -0
- package/util/date-style.js +123 -0
- package/util/parse-datetime.d.ts +4 -3
- package/util/parse-datetime.js +34 -9
- package/util/resolve-column-formats.js +4 -0
- package/util/row-decoder.d.ts +24 -4
- package/util/row-decoder.js +25 -10
- package/util/sql-tag.js +2 -1
- package/util/transaction-command.d.ts +7 -0
- package/util/transaction-command.js +32 -0
- package/util/unspecified-param.d.ts +0 -5
- package/util/unspecified-param.js +1 -10
package/util/row-decoder.d.ts
CHANGED
|
@@ -17,12 +17,28 @@ import type { AnyParseFunction } from '../types.js';
|
|
|
17
17
|
* every other row's bytes in it) alive until released.
|
|
18
18
|
*/
|
|
19
19
|
export declare abstract class RowDecoder {
|
|
20
|
+
/**
|
|
21
|
+
* What `QueryResult.rowType`/`Cursor.rowType` reports for rows this
|
|
22
|
+
* decoder produced - a promise to the caller about their shape, so it
|
|
23
|
+
* is the decoder's to make. `'custom'` here is the honest answer for
|
|
24
|
+
* a decoder nobody else knows anything about; the two built-ins name
|
|
25
|
+
* their own shape, and a subclass of one that still produces that
|
|
26
|
+
* shape inherits the right answer without doing anything.
|
|
27
|
+
*
|
|
28
|
+
* Set it when a subclass changes the shape - a decoder that hands
|
|
29
|
+
* back a lazy view rather than a plain array is not an `'array'`, and
|
|
30
|
+
* a caller that indexes it because the result said so would be
|
|
31
|
+
* reading the wrong thing.
|
|
32
|
+
*/
|
|
33
|
+
readonly rowType: 'array' | 'object' | 'custom';
|
|
20
34
|
abstract decode(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions, fields: FieldInfo[]): any;
|
|
21
35
|
}
|
|
22
36
|
export declare class ArrayRowDecoder extends RowDecoder {
|
|
37
|
+
readonly rowType: "array";
|
|
23
38
|
decode(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions): any[];
|
|
24
39
|
}
|
|
25
40
|
export declare class ObjectRowDecoder extends RowDecoder {
|
|
41
|
+
readonly rowType: "object";
|
|
26
42
|
decode(parsers: AnyParseFunction[], data: Buffer, columnCount: number, options: DataMappingOptions, fields: FieldInfo[]): object;
|
|
27
43
|
}
|
|
28
44
|
export declare const DEFAULT_ARRAY_ROW_DECODER: ArrayRowDecoder;
|
|
@@ -40,10 +56,14 @@ interface RowDecoderOptions {
|
|
|
40
56
|
*/
|
|
41
57
|
export declare function resolveRowDecoder(options: RowDecoderOptions): RowDecoder;
|
|
42
58
|
/**
|
|
43
|
-
* The `rowType` string surfaced on `QueryResult`/`Cursor.rowType`.
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
59
|
+
* The `rowType` string surfaced on `QueryResult`/`Cursor.rowType`.
|
|
60
|
+
*
|
|
61
|
+
* Asked of the decoder rather than worked out from its class: an
|
|
62
|
+
* `instanceof` test answers `'array'` for anything derived from
|
|
63
|
+
* `ArrayRowDecoder`, including a subclass that overrode `decode()` to
|
|
64
|
+
* return something else entirely - which is the only reason to subclass
|
|
65
|
+
* it. The built-ins declare their own shape, so the answers are
|
|
66
|
+
* unchanged, and a subclass that changes the shape can now say so.
|
|
47
67
|
*/
|
|
48
68
|
export declare function resolveRowType(options: RowDecoderOptions): 'array' | 'object' | 'custom';
|
|
49
69
|
export {};
|
package/util/row-decoder.js
CHANGED
|
@@ -15,13 +15,29 @@ import { parseObjectRow, parseRow } from './parse-row.js';
|
|
|
15
15
|
* every other row's bytes in it) alive until released.
|
|
16
16
|
*/
|
|
17
17
|
export class RowDecoder {
|
|
18
|
+
/**
|
|
19
|
+
* What `QueryResult.rowType`/`Cursor.rowType` reports for rows this
|
|
20
|
+
* decoder produced - a promise to the caller about their shape, so it
|
|
21
|
+
* is the decoder's to make. `'custom'` here is the honest answer for
|
|
22
|
+
* a decoder nobody else knows anything about; the two built-ins name
|
|
23
|
+
* their own shape, and a subclass of one that still produces that
|
|
24
|
+
* shape inherits the right answer without doing anything.
|
|
25
|
+
*
|
|
26
|
+
* Set it when a subclass changes the shape - a decoder that hands
|
|
27
|
+
* back a lazy view rather than a plain array is not an `'array'`, and
|
|
28
|
+
* a caller that indexes it because the result said so would be
|
|
29
|
+
* reading the wrong thing.
|
|
30
|
+
*/
|
|
31
|
+
rowType = 'custom';
|
|
18
32
|
}
|
|
19
33
|
export class ArrayRowDecoder extends RowDecoder {
|
|
34
|
+
rowType = 'array';
|
|
20
35
|
decode(parsers, data, columnCount, options) {
|
|
21
36
|
return parseRow(parsers, data, columnCount, options);
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
39
|
export class ObjectRowDecoder extends RowDecoder {
|
|
40
|
+
rowType = 'object';
|
|
25
41
|
decode(parsers, data, columnCount, options, fields) {
|
|
26
42
|
return parseObjectRow(parsers, data, columnCount, options, fields);
|
|
27
43
|
}
|
|
@@ -48,16 +64,15 @@ export function resolveRowDecoder(options) {
|
|
|
48
64
|
: DEFAULT_ARRAY_ROW_DECODER;
|
|
49
65
|
}
|
|
50
66
|
/**
|
|
51
|
-
* The `rowType` string surfaced on `QueryResult`/`Cursor.rowType`.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
67
|
+
* The `rowType` string surfaced on `QueryResult`/`Cursor.rowType`.
|
|
68
|
+
*
|
|
69
|
+
* Asked of the decoder rather than worked out from its class: an
|
|
70
|
+
* `instanceof` test answers `'array'` for anything derived from
|
|
71
|
+
* `ArrayRowDecoder`, including a subclass that overrode `decode()` to
|
|
72
|
+
* return something else entirely - which is the only reason to subclass
|
|
73
|
+
* it. The built-ins declare their own shape, so the answers are
|
|
74
|
+
* unchanged, and a subclass that changes the shape can now say so.
|
|
55
75
|
*/
|
|
56
76
|
export function resolveRowType(options) {
|
|
57
|
-
|
|
58
|
-
if (decoder instanceof ObjectRowDecoder)
|
|
59
|
-
return 'object';
|
|
60
|
-
if (decoder instanceof ArrayRowDecoder)
|
|
61
|
-
return 'array';
|
|
62
|
-
return 'custom';
|
|
77
|
+
return resolveRowDecoder(options).rowType;
|
|
63
78
|
}
|
package/util/sql-tag.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BindParam } from '../connection/bind-param.js';
|
|
2
2
|
import { DataTypeMap, GlobalTypeMap } from '../data-type-map.js';
|
|
3
|
+
import { arrayLeaf } from './array-leaf.js';
|
|
3
4
|
import { escapeIdentifier } from './escape-identifier.js';
|
|
4
5
|
import { escapeLiteral } from './escape-literal.js';
|
|
5
6
|
import { formatDateParam } from './format-datetime.js';
|
|
6
7
|
import { stringifyArrayLiteral } from './stringify-arrayliteral.js';
|
|
7
|
-
import {
|
|
8
|
+
import { isUnspecifiedParam } from './unspecified-param.js';
|
|
8
9
|
/**
|
|
9
10
|
* A statement built by the `sql` tag: its text with the values pulled out.
|
|
10
11
|
*
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Whether `sql` opens or closes a transaction. */
|
|
2
|
+
export declare function isTransactionCommand(sql: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Whether `sql` must not run inside a savepoint - it is a transaction
|
|
5
|
+
* command, or it configures the transaction.
|
|
6
|
+
*/
|
|
7
|
+
export declare function refusesSavepoint(sql: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Statements that open or close a transaction, and so manage their own
|
|
3
|
+
* boundaries: an implicit BEGIN or COMMIT around one would be wrong, and
|
|
4
|
+
* wrapping one in a savepoint - COMMIT, say - is nonsense.
|
|
5
|
+
*/
|
|
6
|
+
const TRANSACTION_COMMAND_PATTERN = /^(\bBEGIN\b|\bCOMMIT\b|\bSTART\b|\bROLLBACK|SAVEPOINT|RELEASE\b)/i;
|
|
7
|
+
/**
|
|
8
|
+
* `SET TRANSACTION`, which configures the transaction it runs in rather
|
|
9
|
+
* than opening or closing one.
|
|
10
|
+
*
|
|
11
|
+
* It needs an answer of its own because the two are not the same
|
|
12
|
+
* question. PostgreSQL refuses two of its forms inside a subtransaction
|
|
13
|
+
* - `SET TRANSACTION ISOLATION LEVEL` and `SET TRANSACTION [NOT]
|
|
14
|
+
* DEFERRABLE`, both 25001 - so the savepoint `rollbackOnError` puts
|
|
15
|
+
* around every statement in a transaction made them impossible to run
|
|
16
|
+
* at all. But the implicit BEGIN that `autoCommit: false` adds is
|
|
17
|
+
* exactly what they need, so answering "transaction command" for them
|
|
18
|
+
* and suppressing both would trade one failure for another.
|
|
19
|
+
*/
|
|
20
|
+
const CONFIGURES_TRANSACTION_PATTERN = /^\bSET\s+TRANSACTION\b/i;
|
|
21
|
+
/** Whether `sql` opens or closes a transaction. */
|
|
22
|
+
export function isTransactionCommand(sql) {
|
|
23
|
+
return TRANSACTION_COMMAND_PATTERN.test(sql);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether `sql` must not run inside a savepoint - it is a transaction
|
|
27
|
+
* command, or it configures the transaction.
|
|
28
|
+
*/
|
|
29
|
+
export function refusesSavepoint(sql) {
|
|
30
|
+
return (TRANSACTION_COMMAND_PATTERN.test(sql) ||
|
|
31
|
+
CONFIGURES_TRANSACTION_PATTERN.test(sql));
|
|
32
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The first value inside `v` that is not itself an array - what an array
|
|
3
|
-
* parameter's element type would be read from. A scalar answers itself.
|
|
4
|
-
*/
|
|
5
|
-
export declare function arrayLeaf(v: any): any;
|
|
6
1
|
/**
|
|
7
2
|
* Whether a parameter goes out with no declared type (OID 0), as text,
|
|
8
3
|
* for the server to resolve from wherever it lands.
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* The first value inside `v` that is not itself an array - what an array
|
|
3
|
-
* parameter's element type would be read from. A scalar answers itself.
|
|
4
|
-
*/
|
|
5
|
-
export function arrayLeaf(v) {
|
|
6
|
-
let x = v;
|
|
7
|
-
while (Array.isArray(x))
|
|
8
|
-
x = x[0];
|
|
9
|
-
return x;
|
|
10
|
-
}
|
|
1
|
+
import { arrayLeaf } from './array-leaf.js';
|
|
11
2
|
/**
|
|
12
3
|
* Whether a parameter goes out with no declared type (OID 0), as text,
|
|
13
4
|
* for the server to resolve from wherever it lands.
|