@m2k-5f/pgtx 2.7.1 → 2.7.3
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 +48 -31
- 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 +182 -166
- package/dist/error.d.ts +4 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +15 -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 +24 -11
- package/dist/protocol/connection-request-writer.d.ts.map +1 -1
- package/dist/protocol/connection-request-writer.js +217 -47
- package/dist/protocol/connection-response-reader.d.ts +5 -15
- package/dist/protocol/connection-response-reader.d.ts.map +1 -1
- package/dist/protocol/connection-response-reader.js +116 -76
- package/dist/protocol/constants.d.ts +37 -30
- package/dist/protocol/constants.d.ts.map +1 -1
- package/dist/protocol/constants.js +35 -29
- package/dist/protocol/socket-authorization.d.ts.map +1 -1
- package/dist/protocol/socket-authorization.js +7 -7
- 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/query.d.ts +16 -20
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +15 -22
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParameterDescription } from "../types";
|
|
2
|
+
import { DescribeType, RequestType } from "./constants";
|
|
2
3
|
export declare class ConnectionRequestBuffer {
|
|
3
4
|
private buffer;
|
|
4
5
|
private offset;
|
|
@@ -8,23 +9,25 @@ export declare class ConnectionRequestBuffer {
|
|
|
8
9
|
private ensureCapacity;
|
|
9
10
|
writeCString(string: string): this;
|
|
10
11
|
writeString(string: string): this;
|
|
11
|
-
writeInt32(number: number): this;
|
|
12
12
|
writeInt16(number: number): this;
|
|
13
|
+
writeInt32(number: number): this;
|
|
13
14
|
writeChar(char: string): this;
|
|
15
|
+
writeByte(byte: number): this;
|
|
16
|
+
writeBigInt64(value: bigint): this;
|
|
17
|
+
writeUInt16(value: number): this;
|
|
18
|
+
writeUInt32(value: number): this;
|
|
19
|
+
writeBytes(value: Uint8Array): this;
|
|
20
|
+
writeInt64(number: number): this;
|
|
21
|
+
writeFloat32(number: number): this;
|
|
22
|
+
writeFloat64(number: number): this;
|
|
14
23
|
startRequest(requestType: RequestType): this;
|
|
15
24
|
startMessage(): this;
|
|
16
25
|
endRequest(): this;
|
|
17
26
|
asBuffer(): Buffer<ArrayBufferLike>;
|
|
18
27
|
clear(): void;
|
|
19
|
-
}
|
|
20
|
-
export declare class ConnectionRequestWriter {
|
|
21
|
-
private buffer;
|
|
22
|
-
private constructor();
|
|
23
|
-
static new(): ConnectionRequestWriter;
|
|
24
28
|
writeQuery(text: string): this;
|
|
25
29
|
writeParse(name: string | "", text: string): this;
|
|
26
|
-
writeDescribe(
|
|
27
|
-
writeBind(portName: string | "", statementName: string | "", params: (string | null)[]): this;
|
|
30
|
+
writeDescribe(type: DescribeType, name: string | ""): this;
|
|
28
31
|
writeClose(name: string): this;
|
|
29
32
|
writeStartup(user: string, database: string): this;
|
|
30
33
|
writeExecute(portName: string | ""): this;
|
|
@@ -33,7 +36,17 @@ export declare class ConnectionRequestWriter {
|
|
|
33
36
|
writePassword(password: string): this;
|
|
34
37
|
writeSaslInitial(mechanism: string, clientFirstMessage: string): this;
|
|
35
38
|
writeSaslResponse(clientFinalMessage: string): this;
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
writeBinaryBool(value: boolean): this;
|
|
40
|
+
writeBinaryInt2(value: number): this;
|
|
41
|
+
writeBinaryInt4(value: number): this;
|
|
42
|
+
writeBinaryInt8(value: number): this;
|
|
43
|
+
writeBinaryBigInt8(value: bigint): this;
|
|
44
|
+
writeBinaryFloat4(value: number): this;
|
|
45
|
+
writeBinaryFloat8(value: number): this;
|
|
46
|
+
writeBinaryBytea(value: Uint8Array): this;
|
|
47
|
+
writeBinaryTimestamp(value: Date): this;
|
|
48
|
+
writeNull(): this;
|
|
49
|
+
private canWriteBinary;
|
|
50
|
+
writeBind(portName: string | "", statementName: string | "", params: unknown[], parameterTypes?: ParameterDescription): this;
|
|
38
51
|
}
|
|
39
52
|
//# 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,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAA6B,YAAY,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAA;AAMhG,qBAAa,uBAAuB;IAE5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,wBAAwB;IAHpC,OAAO;IAOP,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM;IAK3B,OAAO,CAAC,cAAc;IAoBtB,YAAY,CAAC,MAAM,EAAE,MAAM;IAY3B,WAAW,CAAC,MAAM,EAAE,MAAM;IAS1B,UAAU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CAAC,KAAK,EAAE,MAAM;IAO/B,gBAAgB,CAAC,KAAK,EAAE,UAAU;IAOlC,oBAAoB,CAAC,KAAK,EAAE,IAAI;IAWhC,SAAS;IAMT,OAAO,CAAC,cAAc;IAkEtB,SAAS,CACL,QAAQ,EAAE,MAAM,GAAG,EAAE,EACrB,aAAa,EAAE,MAAM,GAAG,EAAE,EAC1B,MAAM,EAAE,OAAO,EAAE,EACjB,cAAc,CAAC,EAAE,oBAAoB;CAoF5C"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prepareValue } from "../utils";
|
|
2
|
+
import { DataTypeOids, RequestTypes } from "./constants";
|
|
3
|
+
const POSTGRES_EPOCH = Date.UTC(2000, 0, 1);
|
|
2
4
|
export class ConnectionRequestBuffer {
|
|
3
5
|
constructor(buffer, offset = 0, lastRequestLenByteOffset = 0) {
|
|
4
6
|
this.buffer = buffer;
|
|
@@ -33,26 +35,73 @@ export class ConnectionRequestBuffer {
|
|
|
33
35
|
this.offset += this.buffer.write(string, this.offset, 'utf-8');
|
|
34
36
|
return this;
|
|
35
37
|
}
|
|
36
|
-
writeInt32(number) {
|
|
37
|
-
this.ensureCapacity(4);
|
|
38
|
-
this.buffer.writeInt32BE(number, this.offset);
|
|
39
|
-
this.offset += 4;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
38
|
writeInt16(number) {
|
|
43
39
|
this.ensureCapacity(2);
|
|
44
40
|
this.buffer.writeInt16BE(number, this.offset);
|
|
45
41
|
this.offset += 2;
|
|
46
42
|
return this;
|
|
47
43
|
}
|
|
44
|
+
writeInt32(number) {
|
|
45
|
+
this.ensureCapacity(4);
|
|
46
|
+
this.buffer.writeInt32BE(number, this.offset);
|
|
47
|
+
this.offset += 4;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
48
50
|
writeChar(char) {
|
|
49
51
|
this.ensureCapacity(1);
|
|
50
52
|
this.buffer[this.offset] = char.charCodeAt(0);
|
|
51
53
|
this.offset++;
|
|
52
54
|
return this;
|
|
53
55
|
}
|
|
56
|
+
writeByte(byte) {
|
|
57
|
+
this.ensureCapacity(1);
|
|
58
|
+
this.buffer[this.offset++] = byte;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
writeBigInt64(value) {
|
|
62
|
+
this.ensureCapacity(8);
|
|
63
|
+
this.buffer.writeBigInt64BE(value, this.offset);
|
|
64
|
+
this.offset += 8;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
writeUInt16(value) {
|
|
68
|
+
this.ensureCapacity(2);
|
|
69
|
+
this.buffer.writeUInt16BE(value, this.offset);
|
|
70
|
+
this.offset += 2;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
writeUInt32(value) {
|
|
74
|
+
this.ensureCapacity(4);
|
|
75
|
+
this.buffer.writeUInt32BE(value, this.offset);
|
|
76
|
+
this.offset += 4;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
writeBytes(value) {
|
|
80
|
+
this.ensureCapacity(value.byteLength);
|
|
81
|
+
this.buffer.set(value, this.offset);
|
|
82
|
+
this.offset += value.byteLength;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
writeInt64(number) {
|
|
86
|
+
this.ensureCapacity(8);
|
|
87
|
+
this.buffer.writeBigInt64BE(BigInt(number), this.offset);
|
|
88
|
+
this.offset += 8;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
writeFloat32(number) {
|
|
92
|
+
this.ensureCapacity(4);
|
|
93
|
+
this.buffer.writeFloatBE(number, this.offset);
|
|
94
|
+
this.offset += 4;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
writeFloat64(number) {
|
|
98
|
+
this.ensureCapacity(8);
|
|
99
|
+
this.buffer.writeDoubleBE(number, this.offset);
|
|
100
|
+
this.offset += 8;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
54
103
|
startRequest(requestType) {
|
|
55
|
-
this.
|
|
104
|
+
this.writeByte(requestType);
|
|
56
105
|
this.lastRequestLenByteOffset = this.offset;
|
|
57
106
|
return this.writeInt32(0);
|
|
58
107
|
}
|
|
@@ -72,57 +121,36 @@ export class ConnectionRequestBuffer {
|
|
|
72
121
|
this.offset = 0;
|
|
73
122
|
this.lastRequestLenByteOffset = 0;
|
|
74
123
|
}
|
|
75
|
-
}
|
|
76
|
-
export class ConnectionRequestWriter {
|
|
77
|
-
constructor(buffer) {
|
|
78
|
-
this.buffer = buffer;
|
|
79
|
-
}
|
|
80
|
-
static new() {
|
|
81
|
-
return new ConnectionRequestWriter(ConnectionRequestBuffer.new(65536));
|
|
82
|
-
}
|
|
83
124
|
writeQuery(text) {
|
|
84
|
-
this.
|
|
125
|
+
this.startRequest(RequestTypes.SimpleQuery)
|
|
85
126
|
.writeCString(text)
|
|
86
127
|
.endRequest();
|
|
87
128
|
return this;
|
|
88
129
|
}
|
|
89
130
|
writeParse(name, text) {
|
|
90
|
-
this.
|
|
131
|
+
this.startRequest(RequestTypes.Parse)
|
|
91
132
|
.writeCString(name)
|
|
92
133
|
.writeCString(text)
|
|
93
134
|
.writeInt16(0)
|
|
94
135
|
.endRequest();
|
|
95
136
|
return this;
|
|
96
137
|
}
|
|
97
|
-
writeDescribe(
|
|
98
|
-
this.
|
|
99
|
-
.writeChar(
|
|
100
|
-
.writeCString(
|
|
138
|
+
writeDescribe(type, name) {
|
|
139
|
+
this.startRequest(RequestTypes.Describe)
|
|
140
|
+
.writeChar(type)
|
|
141
|
+
.writeCString(name)
|
|
101
142
|
.endRequest();
|
|
102
143
|
return this;
|
|
103
144
|
}
|
|
104
|
-
writeBind(portName, statementName, params) {
|
|
105
|
-
const request = this.buffer.startRequest(RequestTypes.Bind)
|
|
106
|
-
.writeCString(portName)
|
|
107
|
-
.writeCString(statementName)
|
|
108
|
-
.writeInt16(0)
|
|
109
|
-
.writeInt16(params.length);
|
|
110
|
-
params.forEach(param => {
|
|
111
|
-
request.writeInt32(param ? Buffer.byteLength(param) : -1);
|
|
112
|
-
param && request.writeString(param);
|
|
113
|
-
});
|
|
114
|
-
request.writeInt16(1).writeInt16(1).endRequest();
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
145
|
writeClose(name) {
|
|
118
|
-
this.
|
|
146
|
+
this.startRequest(RequestTypes.Close)
|
|
119
147
|
.writeChar("P")
|
|
120
148
|
.writeCString(name)
|
|
121
149
|
.endRequest();
|
|
122
150
|
return this;
|
|
123
151
|
}
|
|
124
152
|
writeStartup(user, database) {
|
|
125
|
-
this.
|
|
153
|
+
this.startMessage()
|
|
126
154
|
.writeInt32(196608)
|
|
127
155
|
.writeCString('user').writeCString(user)
|
|
128
156
|
.writeCString('database').writeCString(database)
|
|
@@ -131,30 +159,30 @@ export class ConnectionRequestWriter {
|
|
|
131
159
|
return this;
|
|
132
160
|
}
|
|
133
161
|
writeExecute(portName) {
|
|
134
|
-
this.
|
|
162
|
+
this.startRequest(RequestTypes.Execute)
|
|
135
163
|
.writeCString(portName)
|
|
136
164
|
.writeInt32(0)
|
|
137
165
|
.endRequest();
|
|
138
166
|
return this;
|
|
139
167
|
}
|
|
140
168
|
writeSync() {
|
|
141
|
-
this.
|
|
169
|
+
this.startRequest(RequestTypes.Sync).endRequest();
|
|
142
170
|
return this;
|
|
143
171
|
}
|
|
144
172
|
writeSSLRequest() {
|
|
145
|
-
this.
|
|
173
|
+
this.startMessage()
|
|
146
174
|
.writeInt32(80877103)
|
|
147
175
|
.endRequest();
|
|
148
176
|
return this;
|
|
149
177
|
}
|
|
150
178
|
writePassword(password) {
|
|
151
|
-
this.
|
|
179
|
+
this.startRequest(RequestTypes.Password)
|
|
152
180
|
.writeCString(password)
|
|
153
181
|
.endRequest();
|
|
154
182
|
return this;
|
|
155
183
|
}
|
|
156
184
|
writeSaslInitial(mechanism, clientFirstMessage) {
|
|
157
|
-
this.
|
|
185
|
+
this.startRequest(RequestTypes.Password)
|
|
158
186
|
.writeCString(mechanism)
|
|
159
187
|
.writeInt32(Buffer.byteLength(clientFirstMessage, 'utf-8'))
|
|
160
188
|
.writeString(clientFirstMessage)
|
|
@@ -162,16 +190,158 @@ export class ConnectionRequestWriter {
|
|
|
162
190
|
return this;
|
|
163
191
|
}
|
|
164
192
|
writeSaslResponse(clientFinalMessage) {
|
|
165
|
-
this.
|
|
193
|
+
this.startRequest(RequestTypes.Password)
|
|
166
194
|
.writeString(clientFinalMessage)
|
|
167
195
|
.endRequest();
|
|
168
196
|
return this;
|
|
169
197
|
}
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
writeBinaryBool(value) {
|
|
199
|
+
this.writeInt32(1);
|
|
200
|
+
this.writeByte(value ? 1 : 0);
|
|
201
|
+
return this;
|
|
172
202
|
}
|
|
173
|
-
|
|
174
|
-
this.
|
|
203
|
+
writeBinaryInt2(value) {
|
|
204
|
+
this.writeInt32(2);
|
|
205
|
+
this.writeInt16(value);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
writeBinaryInt4(value) {
|
|
209
|
+
this.writeInt32(4);
|
|
210
|
+
this.writeInt32(value);
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
writeBinaryInt8(value) {
|
|
214
|
+
this.writeInt32(8);
|
|
215
|
+
this.writeInt64(value);
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
writeBinaryBigInt8(value) {
|
|
219
|
+
this.writeInt32(8);
|
|
220
|
+
this.writeBigInt64(value);
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
writeBinaryFloat4(value) {
|
|
224
|
+
this.writeInt32(4);
|
|
225
|
+
this.writeFloat32(value);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
writeBinaryFloat8(value) {
|
|
229
|
+
this.writeInt32(8);
|
|
230
|
+
this.writeFloat64(value);
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
writeBinaryBytea(value) {
|
|
234
|
+
this.writeInt32(value.byteLength);
|
|
235
|
+
this.writeBytes(value);
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
writeBinaryTimestamp(value) {
|
|
239
|
+
const micros = BigInt(value.getTime() - POSTGRES_EPOCH) * 1000n;
|
|
240
|
+
this.writeInt32(8);
|
|
241
|
+
this.writeBigInt64(micros);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
writeNull() {
|
|
245
|
+
this.writeInt32(-1);
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
canWriteBinary(value, oid) {
|
|
249
|
+
if (value == null || !oid) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
switch (oid) {
|
|
253
|
+
case DataTypeOids.Bool:
|
|
254
|
+
return typeof value === "boolean";
|
|
255
|
+
case DataTypeOids.Int2:
|
|
256
|
+
return (typeof value === "number" &&
|
|
257
|
+
Number.isInteger(value) &&
|
|
258
|
+
value >= -32768 &&
|
|
259
|
+
value <= 32767);
|
|
260
|
+
case DataTypeOids.Int4:
|
|
261
|
+
return (typeof value === "number" &&
|
|
262
|
+
Number.isInteger(value) &&
|
|
263
|
+
value >= -2147483648 &&
|
|
264
|
+
value <= 2147483647);
|
|
265
|
+
case DataTypeOids.Int8:
|
|
266
|
+
return (typeof value === "bigint" ||
|
|
267
|
+
(typeof value === "number" &&
|
|
268
|
+
Number.isSafeInteger(value)));
|
|
269
|
+
case DataTypeOids.Float4:
|
|
270
|
+
case DataTypeOids.Float8:
|
|
271
|
+
return (typeof value === "number" &&
|
|
272
|
+
Number.isFinite(value));
|
|
273
|
+
case DataTypeOids.Bytea:
|
|
274
|
+
return (Buffer.isBuffer(value) ||
|
|
275
|
+
value instanceof Uint8Array);
|
|
276
|
+
case DataTypeOids.Timestamp:
|
|
277
|
+
case DataTypeOids.Timestamptz:
|
|
278
|
+
return value instanceof Date;
|
|
279
|
+
default:
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
writeBind(portName, statementName, params, parameterTypes) {
|
|
284
|
+
const binary = params.map((value, i) => this.canWriteBinary(value, parameterTypes?.[i]));
|
|
285
|
+
const request = this.startRequest(RequestTypes.Bind)
|
|
286
|
+
.writeCString(portName)
|
|
287
|
+
.writeCString(statementName)
|
|
288
|
+
.writeInt16(params.length);
|
|
289
|
+
for (const isBinary of binary) {
|
|
290
|
+
request.writeInt16(isBinary ? 1 : 0);
|
|
291
|
+
}
|
|
292
|
+
request.writeInt16(params.length);
|
|
293
|
+
for (let i = 0; i < params.length; i++) {
|
|
294
|
+
const value = params[i];
|
|
295
|
+
if (value == null) {
|
|
296
|
+
request.writeNull();
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (binary[i]) {
|
|
300
|
+
switch (parameterTypes[i]) {
|
|
301
|
+
case DataTypeOids.Bool:
|
|
302
|
+
request.writeBinaryBool(value);
|
|
303
|
+
break;
|
|
304
|
+
case DataTypeOids.Int2:
|
|
305
|
+
request.writeBinaryInt2(value);
|
|
306
|
+
break;
|
|
307
|
+
case DataTypeOids.Int4:
|
|
308
|
+
request.writeBinaryInt4(value);
|
|
309
|
+
break;
|
|
310
|
+
case DataTypeOids.Int8:
|
|
311
|
+
typeof value === "bigint"
|
|
312
|
+
? request.writeBinaryBigInt8(value)
|
|
313
|
+
: request.writeBinaryInt8(value);
|
|
314
|
+
break;
|
|
315
|
+
case DataTypeOids.Float4:
|
|
316
|
+
request.writeBinaryFloat4(value);
|
|
317
|
+
break;
|
|
318
|
+
case DataTypeOids.Float8:
|
|
319
|
+
request.writeBinaryFloat8(value);
|
|
320
|
+
break;
|
|
321
|
+
case DataTypeOids.Bytea:
|
|
322
|
+
request.writeBinaryBytea(value);
|
|
323
|
+
break;
|
|
324
|
+
case DataTypeOids.Timestamp:
|
|
325
|
+
case DataTypeOids.Timestamptz:
|
|
326
|
+
request.writeBinaryTimestamp(value);
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const prepared = prepareValue(value);
|
|
332
|
+
if (prepared === null) {
|
|
333
|
+
request.writeNull();
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
request
|
|
337
|
+
.writeInt32(Buffer.byteLength(prepared))
|
|
338
|
+
.writeString(prepared);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
request
|
|
342
|
+
.writeInt16(1)
|
|
343
|
+
.writeInt16(1)
|
|
344
|
+
.endRequest();
|
|
175
345
|
return this;
|
|
176
346
|
}
|
|
177
347
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthenticationCode, ResponseType, TransactionStatus } from "./constants";
|
|
2
|
-
import { ChannelName, ColumnDescription } from "../types";
|
|
2
|
+
import { ChannelName, ColumnDescription, ParameterDescription } from "../types";
|
|
3
3
|
import { PostgresError } from "../error";
|
|
4
4
|
export declare class ConnectionResponseBuffer {
|
|
5
5
|
private buffer;
|
|
@@ -12,8 +12,8 @@ export declare class ConnectionResponseBuffer {
|
|
|
12
12
|
readCString(): string;
|
|
13
13
|
readRawString(length: number): string;
|
|
14
14
|
hasMore(): boolean;
|
|
15
|
-
readRawBinaryString(length: number): string;
|
|
16
15
|
readBinaryDate(): Date;
|
|
16
|
+
readByte(): number;
|
|
17
17
|
readBinaryTimestamp(): Date;
|
|
18
18
|
readBinaryTime(): string;
|
|
19
19
|
skipBytes(byteCount: number): void;
|
|
@@ -22,16 +22,13 @@ export declare class ConnectionResponseBuffer {
|
|
|
22
22
|
readBool(): boolean;
|
|
23
23
|
readBigInt64(): bigint;
|
|
24
24
|
readInt64(): number;
|
|
25
|
+
readNumeric(): string;
|
|
26
|
+
readBinaryTimetz(): string;
|
|
25
27
|
readFloat32(): number;
|
|
26
28
|
readFloat64(): number;
|
|
27
29
|
readUuid(): string;
|
|
28
30
|
readBytes(length: number): Buffer<ArrayBuffer>;
|
|
29
31
|
getBufferHash(length: number): number;
|
|
30
|
-
}
|
|
31
|
-
export declare class ConnectionResponseReader {
|
|
32
|
-
private buffer;
|
|
33
|
-
private constructor();
|
|
34
|
-
static from(buffer: Buffer): ConnectionResponseReader;
|
|
35
32
|
readType(): {
|
|
36
33
|
type: ResponseType;
|
|
37
34
|
length: number;
|
|
@@ -57,13 +54,6 @@ export declare class ConnectionResponseReader {
|
|
|
57
54
|
payload: string;
|
|
58
55
|
};
|
|
59
56
|
readCommandComplete(): string;
|
|
60
|
-
|
|
61
|
-
hasFullPacket(): boolean;
|
|
62
|
-
getResidualBuffer(): Buffer<ArrayBufferLike>;
|
|
63
|
-
readParseComplete(): void;
|
|
64
|
-
readBindComplete(): void;
|
|
65
|
-
readParameterDescription(): void;
|
|
66
|
-
readNoData(): void;
|
|
67
|
-
skip(count: number): void;
|
|
57
|
+
readParameterDescription(): ParameterDescription;
|
|
68
58
|
}
|
|
69
59
|
//# sourceMappingURL=connection-response-reader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-response-reader.d.ts","sourceRoot":"","sources":["../../src/protocol/connection-response-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"connection-response-reader.d.ts","sourceRoot":"","sources":["../../src/protocol/connection-response-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAyC,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACxH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAOxC,qBAAa,wBAAwB;IAI7B,OAAO,CAAC,MAAM;IAHlB,OAAO,CAAC,KAAK,CAAI;IAEjB,OAAO;IAKP,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM;IAK1B,QAAQ,IAAI,MAAM;IAOlB,SAAS,IAAI,MAAM;IAOnB,SAAS,IAAI,MAAM;IAOnB,WAAW,IAAI,MAAM;IAQrB,aAAa,CAAC,MAAM,EAA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