@m2k-5f/pgtx 2.7.2 → 2.8.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/README.md +65 -37
- package/dist/batch.d.ts +4 -1
- package/dist/batch.d.ts.map +1 -1
- package/dist/batch.js +14 -7
- package/dist/clauses/fragment.clause.js +1 -1
- package/dist/connection.d.ts +17 -16
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +231 -175
- package/dist/error.d.ts +6 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +26 -7
- package/dist/pool.d.ts +1 -1
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +5 -3
- package/dist/protocol/connection-request-writer.d.ts +107 -11
- package/dist/protocol/connection-request-writer.d.ts.map +1 -1
- package/dist/protocol/connection-request-writer.js +442 -48
- package/dist/protocol/connection-response-reader.d.ts +75 -30
- package/dist/protocol/connection-response-reader.d.ts.map +1 -1
- package/dist/protocol/connection-response-reader.js +285 -289
- package/dist/protocol/constants.d.ts +37 -30
- package/dist/protocol/constants.d.ts.map +1 -1
- package/dist/protocol/constants.js +43 -37
- package/dist/protocol/socket-authorization.d.ts.map +1 -1
- package/dist/protocol/socket-authorization.js +3 -3
- package/dist/protocol/socket-connector.d.ts +4 -4
- package/dist/protocol/socket-connector.d.ts.map +1 -1
- package/dist/protocol/socket-connector.js +2 -2
- package/dist/protocol/types.d.ts +14 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +264 -0
- package/dist/query.d.ts +34 -24
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +45 -30
- package/dist/queue.d.ts +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +1 -0
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/template-compiler.d.ts +5 -2
- package/dist/utils/template-compiler.d.ts.map +1 -1
- package/dist/utils/template-compiler.js +4 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +73 -0
- package/package.json +2 -2
package/dist/pool.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Connection } from "./connection";
|
|
|
2
2
|
import { Queue, RingQueue } from "./queue";
|
|
3
3
|
import { Begin, Future, Ok } from "fluent-future";
|
|
4
4
|
import { ErrPoolClosed } from "./error";
|
|
5
|
+
import { compileSqlTemplate } from "./utils";
|
|
5
6
|
/**
|
|
6
7
|
* Connection pool and the main entry point for Pgtx.
|
|
7
8
|
*
|
|
@@ -134,7 +135,7 @@ export class Pool {
|
|
|
134
135
|
* @example
|
|
135
136
|
* for await (const row of pool.stream<User>`SELECT * FROM orders`) { ... }
|
|
136
137
|
*/
|
|
137
|
-
stream(templates, ...
|
|
138
|
+
stream(templates, ...params) {
|
|
138
139
|
if (!this._isOpened)
|
|
139
140
|
throw ErrPoolClosed;
|
|
140
141
|
while (this._available.hasMore) {
|
|
@@ -144,7 +145,7 @@ export class Pool {
|
|
|
144
145
|
continue;
|
|
145
146
|
}
|
|
146
147
|
this._available.push(conn);
|
|
147
|
-
return conn.stream(templates, ...
|
|
148
|
+
return conn.stream(templates, ...params);
|
|
148
149
|
}
|
|
149
150
|
let controller;
|
|
150
151
|
const stream = new ReadableStream({
|
|
@@ -155,7 +156,8 @@ export class Pool {
|
|
|
155
156
|
this.acquire()
|
|
156
157
|
.tap(conn => {
|
|
157
158
|
this.release(conn);
|
|
158
|
-
|
|
159
|
+
const { text, args } = compileSqlTemplate(templates, params);
|
|
160
|
+
conn['_performStream'](text, args, controller);
|
|
159
161
|
})
|
|
160
162
|
.catch(err => {
|
|
161
163
|
controller.error(err);
|
|
@@ -1,30 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PostgresError } from "../error";
|
|
2
|
+
import { StatementMeta } from "../types";
|
|
3
|
+
import { DataTypeOid, DescribeType, RequestType } from "./constants";
|
|
2
4
|
export declare class ConnectionRequestBuffer {
|
|
3
5
|
private buffer;
|
|
4
6
|
private offset;
|
|
5
7
|
private lastRequestLenByteOffset;
|
|
8
|
+
private _markedCaret;
|
|
6
9
|
private constructor();
|
|
7
10
|
static new(capacity: number): ConnectionRequestBuffer;
|
|
11
|
+
get isEmpty(): boolean;
|
|
12
|
+
get hasMore(): boolean;
|
|
13
|
+
mark(): this;
|
|
14
|
+
rollback(): this;
|
|
8
15
|
private ensureCapacity;
|
|
9
16
|
writeCString(string: string): this;
|
|
10
17
|
writeString(string: string): this;
|
|
11
|
-
writeInt32(number: number): this;
|
|
12
18
|
writeInt16(number: number): this;
|
|
19
|
+
writeInt32(number: number): this;
|
|
13
20
|
writeChar(char: string): this;
|
|
21
|
+
writeByte(byte: number): this;
|
|
22
|
+
writeBigInt64(value: bigint): this;
|
|
23
|
+
writeUInt16(value: number): this;
|
|
24
|
+
writeUInt32(value: number): this;
|
|
25
|
+
writeBytes(value: Uint8Array): this;
|
|
26
|
+
writeInt64(number: number): this;
|
|
27
|
+
writeFloat32(number: number): this;
|
|
28
|
+
writeFloat64(number: number): this;
|
|
14
29
|
startRequest(requestType: RequestType): this;
|
|
15
30
|
startMessage(): this;
|
|
16
31
|
endRequest(): this;
|
|
17
32
|
asBuffer(): Buffer<ArrayBufferLike>;
|
|
18
33
|
clear(): void;
|
|
19
|
-
}
|
|
20
|
-
export declare class ConnectionRequestWriter {
|
|
21
|
-
private buffer;
|
|
22
|
-
private constructor();
|
|
23
|
-
static new(): ConnectionRequestWriter;
|
|
24
34
|
writeQuery(text: string): this;
|
|
25
35
|
writeParse(name: string | "", text: string): this;
|
|
26
|
-
writeDescribe(
|
|
27
|
-
writeBind(portName: string | "", statementName: string | "", params: (string | null)[]): this;
|
|
36
|
+
writeDescribe(type: DescribeType, name: string | ""): this;
|
|
28
37
|
writeClose(name: string): this;
|
|
29
38
|
writeStartup(user: string, database: string): this;
|
|
30
39
|
writeExecute(portName: string | ""): this;
|
|
@@ -33,7 +42,94 @@ export declare class ConnectionRequestWriter {
|
|
|
33
42
|
writePassword(password: string): this;
|
|
34
43
|
writeSaslInitial(mechanism: string, clientFirstMessage: string): this;
|
|
35
44
|
writeSaslResponse(clientFinalMessage: string): this;
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
writeBinaryBool(value: boolean): this;
|
|
46
|
+
writeBinaryString(value: string): this;
|
|
47
|
+
writeBinaryInt2(value: number): this;
|
|
48
|
+
writeBinaryInt4(value: number): this;
|
|
49
|
+
writeBinaryInt8(value: number): this;
|
|
50
|
+
writeBinaryBigInt8(value: bigint): this;
|
|
51
|
+
writeBinaryFloat4(value: number): this;
|
|
52
|
+
writeBinaryFloat8(value: number): this;
|
|
53
|
+
writeBinaryBytea(value: Uint8Array): this;
|
|
54
|
+
writeBinaryTimestamp(value: Date): this;
|
|
55
|
+
writeBinaryPoint(value: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
}): this;
|
|
59
|
+
writeBinaryNumeric(value: string): this;
|
|
60
|
+
writeBinaryDate(value: Date): this;
|
|
61
|
+
writeBinaryTime(value: string): this;
|
|
62
|
+
writeBinaryTimetz(value: string): this;
|
|
63
|
+
writeBinaryInterval(value: {
|
|
64
|
+
months: number;
|
|
65
|
+
days: number;
|
|
66
|
+
microseconds: number | bigint;
|
|
67
|
+
}): this;
|
|
68
|
+
writeBinaryJson(value: unknown): this;
|
|
69
|
+
writeBinaryJsonb(value: unknown): this;
|
|
70
|
+
writeBinaryUuid(value: string): this;
|
|
71
|
+
private static readonly PGSQL_AF_INET;
|
|
72
|
+
private static readonly PGSQL_AF_INET6;
|
|
73
|
+
private ipv4ToBytes;
|
|
74
|
+
private ipv6ToBytes;
|
|
75
|
+
writeBinaryInet(value: string, isCidr?: boolean): this;
|
|
76
|
+
writeBinaryCidr(value: string): this;
|
|
77
|
+
writeBinaryMacaddr(value: string): this;
|
|
78
|
+
writeBinaryOid(value: number): this;
|
|
79
|
+
writeBinaryXid(value: number): this;
|
|
80
|
+
writeBinaryCid(value: number): this;
|
|
81
|
+
writeBinaryRegproc(value: number): this;
|
|
82
|
+
writeBinaryLseg(value: {
|
|
83
|
+
a: {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
};
|
|
87
|
+
b: {
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
};
|
|
91
|
+
}): this;
|
|
92
|
+
writeBinaryPath(value: {
|
|
93
|
+
closed: boolean;
|
|
94
|
+
points: {
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
}[];
|
|
98
|
+
}): this;
|
|
99
|
+
writeBinaryBox(value: {
|
|
100
|
+
high: {
|
|
101
|
+
x: number;
|
|
102
|
+
y: number;
|
|
103
|
+
};
|
|
104
|
+
low: {
|
|
105
|
+
x: number;
|
|
106
|
+
y: number;
|
|
107
|
+
};
|
|
108
|
+
}): this;
|
|
109
|
+
writeBinaryPolygon(value: {
|
|
110
|
+
points: {
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
}[];
|
|
114
|
+
}): this;
|
|
115
|
+
writeBinaryLine(value: {
|
|
116
|
+
a: number;
|
|
117
|
+
b: number;
|
|
118
|
+
c: number;
|
|
119
|
+
}): this;
|
|
120
|
+
private writeLengthPrefixed;
|
|
121
|
+
writeBinaryArray(arr: unknown[], elementOid: DataTypeOid, elementWriter: (val: any) => void): this;
|
|
122
|
+
writeBinaryBoolArray(value: (boolean | null | undefined)[]): this;
|
|
123
|
+
writeBinaryInt2Array(value: (number | null | undefined)[]): this;
|
|
124
|
+
writeBinaryInt4Array(value: (number | null | undefined)[]): this;
|
|
125
|
+
writeBinaryInt8Array(value: (number | bigint | null | undefined)[]): this;
|
|
126
|
+
writeBinaryTextArray(value: (string | null | undefined)[]): this;
|
|
127
|
+
writeBinaryVarcharArray(value: (string | null | undefined)[]): this;
|
|
128
|
+
writeBinaryJsonArray(value: (unknown | null | undefined)[]): this;
|
|
129
|
+
writeBinaryJsonbArray(value: (unknown | null | undefined)[]): this;
|
|
130
|
+
writeBinaryUuidArray(value: (string | null | undefined)[]): this;
|
|
131
|
+
writeBinaryNumericArray(value: (number | string | null | undefined)[]): this;
|
|
132
|
+
writeNull(): this;
|
|
133
|
+
writeBind(portName: string | "", meta: StatementMeta, params: unknown[]): PostgresError | null;
|
|
38
134
|
}
|
|
39
135
|
//# sourceMappingURL=connection-request-writer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-request-writer.d.ts","sourceRoot":"","sources":["../../src/protocol/connection-request-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"connection-request-writer.d.ts","sourceRoot":"","sources":["../../src/protocol/connection-request-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,WAAW,EAAgB,YAAY,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAA;AAOhG,qBAAa,uBAAuB;IAE5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,wBAAwB;IAChC,OAAO,CAAC,YAAY;IAJxB,OAAO;IAQP,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM;IAK3B,IAAI,OAAO,YAEV;IAED,IAAI,OAAO,YAEV;IAGD,IAAI;IAMJ,QAAQ;IAMR,OAAO,CAAC,cAAc;IAoBtB,YAAY,CAAC,MAAM,EAAE,MAAM;IAY3B,WAAW,CAAC,MAAM,EAAE,MAAM;IAS1B,UAAU,CAAC,MAAM,EAAE,MAAM;IAUzB,UAAU,CAAC,MAAM,EAAE,MAAM;IAUzB,SAAS,CAAC,IAAI,EAAE,MAAM;IAStB,SAAS,CAAC,IAAI,EAAE,MAAM;IAQtB,aAAa,CAAC,KAAK,EAAE,MAAM;IAS3B,WAAW,CAAC,KAAK,EAAE,MAAM;IASz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