@m2k-5f/pgtx 2.5.1 → 2.5.4
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/dist/clauses/array.clause.js +2 -2
- package/dist/clauses/exclude.clause.d.ts.map +1 -1
- package/dist/clauses/exclude.clause.js +2 -2
- package/dist/clauses/fragment.clause.d.ts.map +1 -1
- package/dist/clauses/fragment.clause.js +2 -5
- package/dist/clauses/iden.caluse.js +1 -1
- package/dist/clauses/insert.clause.d.ts.map +1 -1
- package/dist/clauses/insert.clause.js +10 -9
- package/dist/clauses/literal.clause.js +1 -1
- package/dist/clauses/update.clause.js +2 -2
- package/dist/clauses/where.clause.js +2 -2
- package/dist/connection.d.ts +3 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +45 -38
- package/dist/protocol/connection-request-writer.js +1 -1
- package/dist/protocol/connection-response-reader.d.ts +4 -2
- package/dist/protocol/connection-response-reader.d.ts.map +1 -1
- package/dist/protocol/connection-response-reader.js +69 -21
- package/dist/queue.d.ts +17 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +44 -4
- package/dist/transaction.d.ts +2 -2
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +2 -4
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/template-compiler.d.ts +2 -2
- package/dist/utils/template-compiler.d.ts.map +1 -1
- package/dist/utils/template-compiler.js +17 -9
- package/package.json +8 -5
|
@@ -16,13 +16,13 @@ export class ArrayClause extends Clause {
|
|
|
16
16
|
throw new TypeError(`Array item at index ${index} is undefined`);
|
|
17
17
|
}
|
|
18
18
|
if (index)
|
|
19
|
-
params.text
|
|
19
|
+
params.text += this.separator;
|
|
20
20
|
if (value instanceof Clause) {
|
|
21
21
|
value.mapIntoQuery(params);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
params.args.push(value);
|
|
25
|
-
params.text
|
|
25
|
+
params.text += `$${params.args.length}`;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclude.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/exclude.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,mBAAoB,SAAQ,MAAM;IAEvC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE;IAD7B,OAAO;IAIP,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,mBAAmB;IAI7C,YAAY,CAAC,MAAM,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"exclude.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/exclude.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,mBAAoB,SAAQ,MAAM;IAEvC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE;IAD7B,OAAO;IAIP,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,mBAAmB;IAI7C,YAAY,CAAC,MAAM,EAAE,oBAAoB;CAInD"}
|
|
@@ -8,7 +8,7 @@ export class ExcludeUpdateClause extends Clause {
|
|
|
8
8
|
return new ExcludeUpdateClause(fields);
|
|
9
9
|
}
|
|
10
10
|
mapIntoQuery(params) {
|
|
11
|
-
params.text
|
|
12
|
-
.join(', ')
|
|
11
|
+
params.text += this.fields.map(f => `${f} = EXCLUDED.${f}`)
|
|
12
|
+
.join(', ');
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragment.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/fragment.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAI,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAoB,MAAM,UAAU,CAAC;AAElE,qBAAa,cAAe,SAAQ,MAAM;IAElC,QAAQ,CAAC,SAAS,EAAE,oBAAoB;IACxC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE;IAFxB,OAAO;IAKP,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;IAIpD,YAAY,CAAC,MAAM,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"fragment.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/fragment.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAI,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAoB,MAAM,UAAU,CAAC;AAElE,qBAAa,cAAe,SAAQ,MAAM;IAElC,QAAQ,CAAC,SAAS,EAAE,oBAAoB;IACxC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE;IAFxB,OAAO;IAKP,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;IAIpD,YAAY,CAAC,MAAM,EAAE,oBAAoB;CAMrD"}
|
|
@@ -10,11 +10,8 @@ export class FragmentClause extends Clause {
|
|
|
10
10
|
return new FragmentClause(strings, values);
|
|
11
11
|
}
|
|
12
12
|
mapIntoQuery(params) {
|
|
13
|
-
const compiled = compileSqlTemplate(
|
|
14
|
-
args: this.args,
|
|
15
|
-
templates: this.templates
|
|
16
|
-
}, params.args.length);
|
|
13
|
+
const compiled = compileSqlTemplate(this.templates, this.args, params.args.length);
|
|
17
14
|
params.args.push(...compiled.args);
|
|
18
|
-
params.text
|
|
15
|
+
params.text += compiled.text;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/insert.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,MAAM;IAE/D,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE;IADzB,OAAO;IAIP,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE;IAO5D,YAAY,CAAC,MAAM,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"insert.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/insert.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,MAAM;IAE/D,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE;IADzB,OAAO;IAIP,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE;IAO5D,YAAY,CAAC,MAAM,EAAE,oBAAoB;CAwBrD"}
|
|
@@ -13,20 +13,21 @@ export class InsertClause extends Clause {
|
|
|
13
13
|
mapIntoQuery(params) {
|
|
14
14
|
const columns = Object.keys(this.inserts[0]);
|
|
15
15
|
const columnsCount = columns.length;
|
|
16
|
-
params.text
|
|
16
|
+
params.text += `(${columns.join(', ')}) VALUES `;
|
|
17
17
|
this.inserts.forEach((object, index) => {
|
|
18
18
|
if (Object.keys(object).length !== columnsCount) {
|
|
19
19
|
throw new Error(`all rows must have the same columns`);
|
|
20
20
|
}
|
|
21
21
|
if (index)
|
|
22
|
-
params.text
|
|
23
|
-
params.text
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
params.text += ', ';
|
|
23
|
+
params.text +=
|
|
24
|
+
`(${Object.values(object).map(value => {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return "DEFAULT";
|
|
27
|
+
params.args.push(value);
|
|
28
|
+
return `$${params.args.length}`;
|
|
29
|
+
})
|
|
30
|
+
.join(", ")})`;
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -13,9 +13,9 @@ export class UpdateClause extends Clause {
|
|
|
13
13
|
throw new Error('Update clause has no data to update. All values are `undefined`');
|
|
14
14
|
entries.forEach(([key, value], index) => {
|
|
15
15
|
if (index)
|
|
16
|
-
params.text
|
|
16
|
+
params.text += ', ';
|
|
17
17
|
params.args.push(value);
|
|
18
|
-
params.text
|
|
18
|
+
params.text += `${key} = $${params.args.length}`;
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -13,9 +13,9 @@ export class WhereClause extends Clause {
|
|
|
13
13
|
throw new Error('Where clause has no data to update. All values are `undefined`');
|
|
14
14
|
entries.forEach(([key, value], index) => {
|
|
15
15
|
if (index)
|
|
16
|
-
params.text
|
|
16
|
+
params.text += ' AND ';
|
|
17
17
|
params.args.push(value);
|
|
18
|
-
params.text
|
|
18
|
+
params.text += `"${key}" = $${params.args.length}`;
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
}
|
package/dist/connection.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export type ConnectionParams = {
|
|
|
12
12
|
logLevel?: LogLevel;
|
|
13
13
|
int8toBigint?: boolean;
|
|
14
14
|
queryTimeout?: number;
|
|
15
|
+
batchCapacity?: number;
|
|
16
|
+
flushShedule?: "nextTick" | "Immediate";
|
|
15
17
|
};
|
|
16
18
|
export type StatementName = Branded<string, 'StatementName'>;
|
|
17
19
|
export type QueryText = Branded<string, 'QueryText'>;
|
|
@@ -53,7 +55,7 @@ export declare class Connection {
|
|
|
53
55
|
private _isReconnecting;
|
|
54
56
|
private _socket;
|
|
55
57
|
private _writer;
|
|
56
|
-
private
|
|
58
|
+
private _batchQueue;
|
|
57
59
|
private _described;
|
|
58
60
|
private _describingPending;
|
|
59
61
|
private _parsed;
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAK3C,OAAO,EAAS,MAAM,EAAM,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGvC,KAAK,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AAErD,MAAM,MAAM,gBAAgB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAK3C,OAAO,EAAS,MAA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,OAAO,CAAC,qBAAqB;YAWf,UAAU;IAqBxB,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,aAAa;IA2IrB;;;OAGG;IACH,IAAI,QAAQ,YAEX;IAGD;;;;;;;;;OASG;IACH,KAAK;CAQR"}
|
package/dist/connection.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { nextTick } from "process";
|
|
1
2
|
import { ConnectionRequestWriter } from "./protocol/connection-request-writer";
|
|
2
3
|
import { createAuthorizedSocket } from "./protocol/socket-authorization";
|
|
3
4
|
import { ResponseTypes } from "./protocol/constants";
|
|
4
5
|
import { compileSqlTemplate } from "./utils/template-compiler";
|
|
5
6
|
import { Transaction } from "./transaction";
|
|
6
7
|
import { SocketConnector } from "./protocol/socket-connector";
|
|
7
|
-
import { Queue } from "./queue";
|
|
8
|
+
import { Queue, RingQueue } from "./queue";
|
|
8
9
|
import { Query, QueryState, StreamQuery } from "./query";
|
|
9
10
|
import { sql } from ".";
|
|
10
11
|
import { Begin, Future, Ok } from 'fluent-future';
|
|
11
12
|
import { PostgresError } from "./error";
|
|
13
|
+
const ErrBatchOverflowed = new PostgresError(`BatchOverflowError: Connection queue capacity exceeded.
|
|
14
|
+
Please increase the batch capacity parameter in your connection config.`);
|
|
12
15
|
const ErrConnectionClosed = new PostgresError("Connection is closed", 'connection_closed', "", "ERROR");
|
|
13
16
|
const ErrConnectionReconnecring = new PostgresError("Connection are reconnecting", "connection_reconnecting", "", "ERROR");
|
|
14
17
|
/**
|
|
@@ -53,7 +56,7 @@ export class Connection {
|
|
|
53
56
|
this._isFlushing = false;
|
|
54
57
|
this._isOpened = true;
|
|
55
58
|
this._isReconnecting = false;
|
|
56
|
-
this.
|
|
59
|
+
this._batchQueue = new Queue();
|
|
57
60
|
this._described = new Map();
|
|
58
61
|
this._describingPending = new Set();
|
|
59
62
|
this._parsed = new Map();
|
|
@@ -62,7 +65,10 @@ export class Connection {
|
|
|
62
65
|
this._stmtCounter = 0;
|
|
63
66
|
this.params = params;
|
|
64
67
|
this._logLevel = logLevel;
|
|
65
|
-
this._socket = new SocketConnector(socket, (type, _, reader) => this._handlePacket(type, reader), (err) =>
|
|
68
|
+
this._socket = new SocketConnector(socket, (type, _, reader) => this._handlePacket(type, reader), (err) => {
|
|
69
|
+
// console.log(err)
|
|
70
|
+
this._registerReconnect();
|
|
71
|
+
});
|
|
66
72
|
this._writer = writer;
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
@@ -114,13 +120,13 @@ export class Connection {
|
|
|
114
120
|
*/
|
|
115
121
|
query(templates, ...params) {
|
|
116
122
|
this._checkOpened();
|
|
117
|
-
|
|
118
|
-
const { text, args } = compileSqlTemplate({ templates, args: params });
|
|
123
|
+
const { text, args } = compileSqlTemplate(templates, params);
|
|
119
124
|
if (this._logLevel === 'query') {
|
|
120
125
|
console.log(`\nQUERY: ${text}\n${args.length !== 0 ? `ARGUMENTS: [${args}]\n` : ""}`);
|
|
121
126
|
}
|
|
122
127
|
const query = this._createQuery(text, args);
|
|
123
|
-
this._writeQuery(query)
|
|
128
|
+
if (this._writeQuery(query))
|
|
129
|
+
return Future.reject(ErrBatchOverflowed);
|
|
124
130
|
query.startTimeout(this.params.queryTimeout || 30000);
|
|
125
131
|
return query.future;
|
|
126
132
|
}
|
|
@@ -246,8 +252,7 @@ export class Connection {
|
|
|
246
252
|
*/
|
|
247
253
|
stream(templates, ...params) {
|
|
248
254
|
this._checkOpened();
|
|
249
|
-
|
|
250
|
-
const { text, args } = compileSqlTemplate({ templates, args: params });
|
|
255
|
+
const { text, args } = compileSqlTemplate(templates, params);
|
|
251
256
|
if (this._logLevel === 'query') {
|
|
252
257
|
console.log(`\nQUERY: ${text}\n${args.length !== 0 ? `ARGUMENTS: [${args}]\n` : ""}`);
|
|
253
258
|
}
|
|
@@ -258,19 +263,20 @@ export class Connection {
|
|
|
258
263
|
}
|
|
259
264
|
});
|
|
260
265
|
const query = this._createStream(text, args, controller);
|
|
261
|
-
this._writeQuery(query)
|
|
266
|
+
if (this._writeQuery(query))
|
|
267
|
+
throw ErrBatchOverflowed;
|
|
262
268
|
query.startTimeout(this.params.queryTimeout || 30000);
|
|
263
269
|
return stream;
|
|
264
270
|
}
|
|
265
271
|
_streamWithController(templates, params, controller) {
|
|
266
272
|
this._checkOpened();
|
|
267
|
-
|
|
268
|
-
const { text, args } = compileSqlTemplate({ templates, args: params });
|
|
273
|
+
const { text, args } = compileSqlTemplate(templates, params);
|
|
269
274
|
if (this._logLevel === 'query') {
|
|
270
275
|
console.log(`\nQUERY: ${text}\n${args.length !== 0 ? `ARGUMENTS: [${args}]\n` : ""}`);
|
|
271
276
|
}
|
|
272
277
|
const query = this._createStream(text, args, controller);
|
|
273
|
-
this._writeQuery(query)
|
|
278
|
+
if (this._writeQuery(query))
|
|
279
|
+
throw ErrBatchOverflowed;
|
|
274
280
|
query.startTimeout(this.params.queryTimeout || 30000);
|
|
275
281
|
return query;
|
|
276
282
|
}
|
|
@@ -333,34 +339,34 @@ export class Connection {
|
|
|
333
339
|
}
|
|
334
340
|
}
|
|
335
341
|
_writeQuery(query) {
|
|
342
|
+
const batch = this._registerFlush();
|
|
343
|
+
if (batch.isFull)
|
|
344
|
+
return true;
|
|
345
|
+
batch.push(query);
|
|
336
346
|
if (query.state === QueryState.Parsing) {
|
|
337
347
|
this._writer
|
|
338
348
|
.writeParse(query.statementName, query.text)
|
|
339
|
-
.writeDescribe(query.statementName)
|
|
340
|
-
.writeBind("", query.statementName, query.args)
|
|
341
|
-
.writeExecute("");
|
|
349
|
+
.writeDescribe(query.statementName);
|
|
342
350
|
}
|
|
343
351
|
if (query.state === QueryState.Describing) {
|
|
344
352
|
this._writer
|
|
345
|
-
.writeDescribe(query.statementName)
|
|
346
|
-
.writeBind("", query.statementName, query.args)
|
|
347
|
-
.writeExecute("");
|
|
348
|
-
}
|
|
349
|
-
if (query.state === QueryState.Executing) {
|
|
350
|
-
this._writer
|
|
351
|
-
.writeBind("", query.statementName, query.args)
|
|
352
|
-
.writeExecute("");
|
|
353
|
+
.writeDescribe(query.statementName);
|
|
353
354
|
}
|
|
354
|
-
this.
|
|
355
|
+
this._writer
|
|
356
|
+
.writeBind("", query.statementName, query.args)
|
|
357
|
+
.writeExecute("");
|
|
355
358
|
}
|
|
356
359
|
_registerFlush() {
|
|
357
360
|
if (!this._isFlushing) {
|
|
358
361
|
this._isFlushing = true;
|
|
359
|
-
this.
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
362
|
+
const batch = new RingQueue(this.params.batchCapacity);
|
|
363
|
+
this._batchQueue.push(batch);
|
|
364
|
+
this.params.flushShedule === 'nextTick'
|
|
365
|
+
? nextTick(() => this._flush())
|
|
366
|
+
: setImmediate(() => this._flush());
|
|
367
|
+
return batch;
|
|
363
368
|
}
|
|
369
|
+
return this._batchQueue.last;
|
|
364
370
|
}
|
|
365
371
|
_flush() {
|
|
366
372
|
if (!this._isOpened) {
|
|
@@ -369,15 +375,15 @@ export class Connection {
|
|
|
369
375
|
}
|
|
370
376
|
if (this._isReconnecting) {
|
|
371
377
|
this._reconnect().then(() => {
|
|
372
|
-
this._isFlushing = false;
|
|
373
378
|
this._socket.write(this._writer.writeSync());
|
|
374
379
|
this._writer.clear();
|
|
380
|
+
this._isFlushing = false;
|
|
375
381
|
});
|
|
376
382
|
}
|
|
377
383
|
else {
|
|
378
|
-
this._isFlushing = false;
|
|
379
384
|
this._socket.write(this._writer.writeSync());
|
|
380
385
|
this._writer.clear();
|
|
386
|
+
this._isFlushing = false;
|
|
381
387
|
}
|
|
382
388
|
}
|
|
383
389
|
_registerReconnect() {
|
|
@@ -393,6 +399,7 @@ export class Connection {
|
|
|
393
399
|
this._rejectPipeline(cause);
|
|
394
400
|
}
|
|
395
401
|
async _reconnect() {
|
|
402
|
+
console.log('reconnecting');
|
|
396
403
|
this._resetConnectionState(ErrConnectionReconnecring);
|
|
397
404
|
const socket = await createAuthorizedSocket(ConnectionRequestWriter.new(), this.params);
|
|
398
405
|
const connector = new SocketConnector(socket, (type, _, reader) => this._handlePacket(type, reader), (err) => this._registerReconnect());
|
|
@@ -409,12 +416,12 @@ export class Connection {
|
|
|
409
416
|
return Promise.all(promises);
|
|
410
417
|
}
|
|
411
418
|
_getCurrentQuery() {
|
|
412
|
-
return this.
|
|
419
|
+
return this._batchQueue.current.current;
|
|
413
420
|
}
|
|
414
421
|
_rejectPipeline(error) {
|
|
415
|
-
if (this.
|
|
422
|
+
if (this._batchQueue.isFree)
|
|
416
423
|
return;
|
|
417
|
-
const queue = this.
|
|
424
|
+
const queue = this._batchQueue.current;
|
|
418
425
|
while (queue.hasMore) {
|
|
419
426
|
queue.shift.reject(error);
|
|
420
427
|
}
|
|
@@ -477,7 +484,7 @@ export class Connection {
|
|
|
477
484
|
case ResponseTypes.ComandComplete:
|
|
478
485
|
{
|
|
479
486
|
reader.readCommandComplete();
|
|
480
|
-
if (this.
|
|
487
|
+
if (this._batchQueue.isFree) {
|
|
481
488
|
this.close();
|
|
482
489
|
break;
|
|
483
490
|
}
|
|
@@ -487,7 +494,7 @@ export class Connection {
|
|
|
487
494
|
break;
|
|
488
495
|
}
|
|
489
496
|
query.state = QueryState.Completed;
|
|
490
|
-
this.
|
|
497
|
+
this._batchQueue.current.next();
|
|
491
498
|
query.resolve();
|
|
492
499
|
}
|
|
493
500
|
break;
|
|
@@ -513,7 +520,7 @@ export class Connection {
|
|
|
513
520
|
case ResponseTypes.ReadyForQuery:
|
|
514
521
|
{
|
|
515
522
|
reader.readReadyForQuery();
|
|
516
|
-
this.
|
|
523
|
+
this._batchQueue.next();
|
|
517
524
|
}
|
|
518
525
|
break;
|
|
519
526
|
case ResponseTypes.Notice:
|
|
@@ -556,9 +563,9 @@ export class Connection {
|
|
|
556
563
|
close() {
|
|
557
564
|
this._isOpened = false;
|
|
558
565
|
this._socket.destroy();
|
|
559
|
-
while (this.
|
|
566
|
+
while (this._batchQueue.hasMore) {
|
|
560
567
|
this._rejectPipeline(ErrConnectionClosed);
|
|
561
|
-
this.
|
|
568
|
+
this._batchQueue.next();
|
|
562
569
|
}
|
|
563
570
|
}
|
|
564
571
|
}
|
|
@@ -6,7 +6,7 @@ export class ConnectionRequestBuffer {
|
|
|
6
6
|
this.lastRequestLenByteOffset = lastRequestLenByteOffset;
|
|
7
7
|
}
|
|
8
8
|
static new(capacity) {
|
|
9
|
-
return new ConnectionRequestBuffer(Buffer.
|
|
9
|
+
return new ConnectionRequestBuffer(Buffer.allocUnsafe(capacity));
|
|
10
10
|
}
|
|
11
11
|
ensureCapacity(needed) {
|
|
12
12
|
const required = needed + this.offset;
|
|
@@ -12,7 +12,6 @@ export declare class ConnectionResponseBuffer {
|
|
|
12
12
|
readInt16(): number;
|
|
13
13
|
readCString(): string;
|
|
14
14
|
readRawString(length: number): string;
|
|
15
|
-
readBytes(length: number): Buffer;
|
|
16
15
|
hasMore(): boolean;
|
|
17
16
|
readRawBinaryString(length: number): string;
|
|
18
17
|
readBinaryDate(): Date;
|
|
@@ -24,7 +23,10 @@ export declare class ConnectionResponseBuffer {
|
|
|
24
23
|
readBool(): boolean;
|
|
25
24
|
readBigInt64(): bigint;
|
|
26
25
|
readInt64(): number;
|
|
26
|
+
readFloat32(): number;
|
|
27
27
|
readFloat64(): number;
|
|
28
|
+
readUuid(): string;
|
|
29
|
+
readBytes(length: number): Buffer<ArrayBuffer>;
|
|
28
30
|
getBufferHash(length: number): number;
|
|
29
31
|
}
|
|
30
32
|
export declare class ConnectionResponseReader {
|
|
@@ -37,7 +39,7 @@ export declare class ConnectionResponseReader {
|
|
|
37
39
|
length: number;
|
|
38
40
|
};
|
|
39
41
|
readAuthentication(): AuthenticationCode;
|
|
40
|
-
readMD5Salt(): Buffer<
|
|
42
|
+
readMD5Salt(): Buffer<ArrayBuffer>;
|
|
41
43
|
readParameterStatus(): {
|
|
42
44
|
name: string;
|
|
43
45
|
value: string;
|
|
@@ -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,EAA6B,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC5G,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAM3C,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,EAAE,MAAM,GAAG,MAAM;IAOrC,
|
|
1
|
+
{"version":3,"file":"connection-response-reader.d.ts","sourceRoot":"","sources":["../../src/protocol/connection-response-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA6B,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC5G,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAM3C,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,EAAE,MAAM,GAAG,MAAM;IAOrC,OAAO,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, this.caret + length);
|
|
41
|
-
this.caret += length;
|
|
42
|
-
return slice;
|
|
43
|
-
}
|
|
44
39
|
hasMore() {
|
|
45
40
|
return this.caret < this.buffer.length;
|
|
46
41
|
}
|
|
@@ -99,11 +94,30 @@ export class ConnectionResponseBuffer {
|
|
|
99
94
|
this.caret += 8;
|
|
100
95
|
return (hi * 4294967296) + lo;
|
|
101
96
|
}
|
|
97
|
+
readFloat32() {
|
|
98
|
+
const value = this.buffer.readFloatBE(this.caret);
|
|
99
|
+
this.caret += 4;
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
102
|
readFloat64() {
|
|
103
103
|
const value = this.buffer.readDoubleBE(this.caret);
|
|
104
104
|
this.caret += 8;
|
|
105
105
|
return value;
|
|
106
106
|
}
|
|
107
|
+
readUuid() {
|
|
108
|
+
const buf = this.readBytes(16);
|
|
109
|
+
return buf.toString('hex', 0, 4) + '-' +
|
|
110
|
+
buf.toString('hex', 4, 6) + '-' +
|
|
111
|
+
buf.toString('hex', 6, 8) + '-' +
|
|
112
|
+
buf.toString('hex', 8, 10) + '-' +
|
|
113
|
+
buf.toString('hex', 10, 16);
|
|
114
|
+
}
|
|
115
|
+
readBytes(length) {
|
|
116
|
+
const result = Buffer.allocUnsafe(length);
|
|
117
|
+
this.buffer.copy(result, 0, this.caret, this.caret + length);
|
|
118
|
+
this.caret += length;
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
107
121
|
getBufferHash(length) {
|
|
108
122
|
let hash = 2166136261;
|
|
109
123
|
const end = this.caret + length;
|
|
@@ -228,19 +242,17 @@ export class ConnectionResponseReader {
|
|
|
228
242
|
for (let i = 0; i < fieldsCount; i++) {
|
|
229
243
|
const fieldLength = this.buffer.readInt32();
|
|
230
244
|
const desc = descriptions[i];
|
|
231
|
-
const key = desc
|
|
245
|
+
const key = desc.name;
|
|
232
246
|
if (fieldLength === -1) {
|
|
233
247
|
row[key] = null;
|
|
234
248
|
continue;
|
|
235
249
|
}
|
|
236
|
-
const oid = desc
|
|
250
|
+
const oid = desc.typeOID;
|
|
237
251
|
switch (oid) {
|
|
238
|
-
case DataTypeOids.Int4:
|
|
239
|
-
row[key] = this.buffer.readInt32();
|
|
240
|
-
break;
|
|
241
252
|
case DataTypeOids.Text:
|
|
242
253
|
case DataTypeOids.Varchar:
|
|
243
254
|
case DataTypeOids.Char:
|
|
255
|
+
case DataTypeOids.Bpchar:
|
|
244
256
|
{
|
|
245
257
|
if (fieldLength <= 32) {
|
|
246
258
|
let cacheForColumn = columnValueCache.get(i);
|
|
@@ -267,36 +279,72 @@ export class ConnectionResponseReader {
|
|
|
267
279
|
}
|
|
268
280
|
break;
|
|
269
281
|
case DataTypeOids.Int2:
|
|
270
|
-
|
|
282
|
+
{
|
|
283
|
+
row[key] = this.buffer.readInt16();
|
|
284
|
+
}
|
|
271
285
|
break;
|
|
272
|
-
case DataTypeOids.
|
|
273
|
-
|
|
286
|
+
case DataTypeOids.Int4:
|
|
287
|
+
{
|
|
288
|
+
row[key] = this.buffer.readInt32();
|
|
289
|
+
}
|
|
274
290
|
break;
|
|
275
291
|
case DataTypeOids.Int8:
|
|
276
292
|
{
|
|
277
293
|
row[key] = int8toBigint ? this.buffer.readBigInt64() : this.buffer.readInt64();
|
|
278
294
|
}
|
|
279
295
|
break;
|
|
296
|
+
case DataTypeOids.Float4:
|
|
297
|
+
{
|
|
298
|
+
row[key] = this.buffer.readFloat32();
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
280
301
|
case DataTypeOids.Float8:
|
|
281
|
-
|
|
302
|
+
{
|
|
303
|
+
row[key] = this.buffer.readFloat64();
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
case DataTypeOids.Bool:
|
|
307
|
+
{
|
|
308
|
+
row[key] = this.buffer.readBool();
|
|
309
|
+
}
|
|
310
|
+
break;
|
|
311
|
+
case DataTypeOids.Bytea:
|
|
312
|
+
{
|
|
313
|
+
row[key] = this.buffer.readBytes(fieldLength);
|
|
314
|
+
}
|
|
282
315
|
break;
|
|
283
316
|
case DataTypeOids.Jsonb:
|
|
284
|
-
|
|
285
|
-
|
|
317
|
+
{
|
|
318
|
+
this.buffer.skipBytes(1);
|
|
319
|
+
row[key] = JSON.parse(this.buffer.readRawString(fieldLength - 1));
|
|
320
|
+
}
|
|
286
321
|
break;
|
|
287
322
|
case DataTypeOids.Json:
|
|
288
|
-
|
|
323
|
+
{
|
|
324
|
+
row[key] = JSON.parse(this.buffer.readRawString(fieldLength));
|
|
325
|
+
}
|
|
289
326
|
break;
|
|
290
327
|
case DataTypeOids.Date:
|
|
291
|
-
|
|
328
|
+
{
|
|
329
|
+
row[key] = this.buffer.readBinaryDate();
|
|
330
|
+
}
|
|
292
331
|
break;
|
|
293
332
|
case DataTypeOids.Timestamp:
|
|
294
333
|
case DataTypeOids.Timestamptz:
|
|
295
|
-
|
|
334
|
+
{
|
|
335
|
+
row[key] = this.buffer.readBinaryTimestamp();
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
case DataTypeOids.Uuid:
|
|
339
|
+
{
|
|
340
|
+
row[key] = this.buffer.readUuid();
|
|
341
|
+
}
|
|
296
342
|
break;
|
|
297
343
|
default:
|
|
298
|
-
|
|
299
|
-
|
|
344
|
+
{
|
|
345
|
+
this.buffer.skipBytes(fieldLength);
|
|
346
|
+
row[key] = null;
|
|
347
|
+
}
|
|
300
348
|
break;
|
|
301
349
|
}
|
|
302
350
|
}
|
package/dist/queue.d.ts
CHANGED
|
@@ -10,4 +10,21 @@ export declare class Queue<T> {
|
|
|
10
10
|
get hasMore(): boolean;
|
|
11
11
|
get isFree(): boolean;
|
|
12
12
|
}
|
|
13
|
+
export declare class RingQueue<T> {
|
|
14
|
+
private readonly _queue;
|
|
15
|
+
private readonly _mask;
|
|
16
|
+
private _head;
|
|
17
|
+
private _tail;
|
|
18
|
+
private _size;
|
|
19
|
+
constructor(requestedCapacity?: number);
|
|
20
|
+
next(): void;
|
|
21
|
+
get current(): T;
|
|
22
|
+
get last(): T;
|
|
23
|
+
get shift(): T;
|
|
24
|
+
push(item: T): void;
|
|
25
|
+
get size(): number;
|
|
26
|
+
get hasMore(): boolean;
|
|
27
|
+
get isFree(): boolean;
|
|
28
|
+
get isFull(): boolean;
|
|
29
|
+
}
|
|
13
30
|
//# sourceMappingURL=queue.d.ts.map
|
package/dist/queue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK,CAAC,CAAC;IAChB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAI;IAEpB,IAAI;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK,CAAC,CAAC;IAChB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAI;IAEpB,IAAI;IAUJ,IAAI,OAAO,MAEV;IAED,IAAI,IAAI,MAA+C;IAGvD,IAAI,KAAK,MAKR;IAGD,IAAI,CAAC,IAAI,EAAE,CAAC;IAIZ,IAAI,IAAI,WAEP;IAGD,IAAI,OAAO,YAEV;IAGD,IAAI,MAAM,YAA+C;CAC5D;AAID,qBAAa,SAAS,CAAC,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAK;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAE9B,OAAO,CAAC,KAAK,CAAI;IACjB,OAAO,CAAC,KAAK,CAAI;IACjB,OAAO,CAAC,KAAK,CAAI;gBAEL,iBAAiB,SAAQ;IAOrC,IAAI;IAMJ,IAAI,OAAO,MAEV;IAED,IAAI,IAAI,MAEP;IAED,IAAI,KAAK,MAIR;IAED,IAAI,CAAC,IAAI,EAAE,CAAC;IAMZ,IAAI,IAAI,WAEP;IAED,IAAI,OAAO,YAEV;IAED,IAAI,MAAM,YAET;IAED,IAAI,MAAM,YAET;CACJ"}
|
package/dist/queue.js
CHANGED
|
@@ -4,11 +4,8 @@ export class Queue {
|
|
|
4
4
|
this._pointer = 0;
|
|
5
5
|
}
|
|
6
6
|
next() {
|
|
7
|
+
this._queue[this._pointer] = undefined;
|
|
7
8
|
this._pointer++;
|
|
8
|
-
if (this._pointer > 10000) {
|
|
9
|
-
this._queue.splice(0, this._pointer);
|
|
10
|
-
this._pointer = 0;
|
|
11
|
-
}
|
|
12
9
|
if (this._pointer >= this._queue.length) {
|
|
13
10
|
this._queue.length = 0;
|
|
14
11
|
this._pointer = 0;
|
|
@@ -34,3 +31,46 @@ export class Queue {
|
|
|
34
31
|
}
|
|
35
32
|
get isFree() { return this._pointer >= this._queue.length; }
|
|
36
33
|
}
|
|
34
|
+
export class RingQueue {
|
|
35
|
+
constructor(requestedCapacity = 20000) {
|
|
36
|
+
this._head = 0;
|
|
37
|
+
this._tail = 0;
|
|
38
|
+
this._size = 0;
|
|
39
|
+
const capacity = 2 ** Math.ceil(Math.log2(requestedCapacity));
|
|
40
|
+
this._queue = new Array();
|
|
41
|
+
this._mask = capacity - 1;
|
|
42
|
+
}
|
|
43
|
+
next() {
|
|
44
|
+
this._queue[this._head] = undefined;
|
|
45
|
+
this._head = (this._head + 1) & this._mask;
|
|
46
|
+
this._size--;
|
|
47
|
+
}
|
|
48
|
+
get current() {
|
|
49
|
+
return this._queue[this._head];
|
|
50
|
+
}
|
|
51
|
+
get last() {
|
|
52
|
+
return this._queue[(this._tail - 1) & this._mask];
|
|
53
|
+
}
|
|
54
|
+
get shift() {
|
|
55
|
+
const item = this.current;
|
|
56
|
+
this.next();
|
|
57
|
+
return item;
|
|
58
|
+
}
|
|
59
|
+
push(item) {
|
|
60
|
+
this._queue[this._tail] = item;
|
|
61
|
+
this._tail = (this._tail + 1) & this._mask;
|
|
62
|
+
this._size++;
|
|
63
|
+
}
|
|
64
|
+
get size() {
|
|
65
|
+
return this._size;
|
|
66
|
+
}
|
|
67
|
+
get hasMore() {
|
|
68
|
+
return this._size !== 0;
|
|
69
|
+
}
|
|
70
|
+
get isFree() {
|
|
71
|
+
return this._size === 0;
|
|
72
|
+
}
|
|
73
|
+
get isFull() {
|
|
74
|
+
return this._size === this._mask + 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
package/dist/transaction.d.ts
CHANGED
|
@@ -17,11 +17,11 @@ export declare class Transaction {
|
|
|
17
17
|
/**
|
|
18
18
|
* Commits the current transaction.
|
|
19
19
|
*/
|
|
20
|
-
commit(): Future<
|
|
20
|
+
commit(): Future<Record<string, any>[], any>;
|
|
21
21
|
/**
|
|
22
22
|
* Rolls back the current transaction.
|
|
23
23
|
*/
|
|
24
|
-
rollback(): Future<
|
|
24
|
+
rollback(): Future<Record<string, any>[], any>;
|
|
25
25
|
/**
|
|
26
26
|
* Executes a query within the current transaction.
|
|
27
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC;;;GAGG;AACH,qBAAa,WAAW;IAIhB,QAAQ,CAAC,IAAI,EAAE,UAAU;IAH7B,OAAO,CAAC,UAAU,CAAiB;gBAGtB,IAAI,EAAE,UAAU;IAG7B;;OAEG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACI,MAAM;
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC;;;GAGG;AACH,qBAAa,WAAW;IAIhB,QAAQ,CAAC,IAAI,EAAE,UAAU;IAH7B,OAAO,CAAC,UAAU,CAAiB;gBAGtB,IAAI,EAAE,UAAU;IAG7B;;OAEG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACI,MAAM;IAOb;;OAEG;IACI,QAAQ;IAOf;;OAEG;IACI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;IAK3F;;;;;;;;;OASG;IACI,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC;CAWjG"}
|
package/dist/transaction.js
CHANGED
|
@@ -26,8 +26,7 @@ export class Transaction {
|
|
|
26
26
|
commit() {
|
|
27
27
|
this.checkActive();
|
|
28
28
|
return this.conn.query `COMMIT`
|
|
29
|
-
.tap(() =>
|
|
30
|
-
.map(() => { });
|
|
29
|
+
.tap(() => this.isFinished = true);
|
|
31
30
|
}
|
|
32
31
|
/**
|
|
33
32
|
* Rolls back the current transaction.
|
|
@@ -35,8 +34,7 @@ export class Transaction {
|
|
|
35
34
|
rollback() {
|
|
36
35
|
this.checkActive();
|
|
37
36
|
return this.conn.query `ROLLBACK`
|
|
38
|
-
.tap(() =>
|
|
39
|
-
.map(() => { });
|
|
37
|
+
.tap(() => this.isFinished = true);
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
40
|
* Executes a query within the current transaction.
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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iBAAiB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,WAAW,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG;IAAC,OAAO,EAAE,KAAK,CAAA;CAAC,CAAA;AAEpD,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CompiledSqlQuery
|
|
2
|
-
export declare function compileSqlTemplate(
|
|
1
|
+
import { CompiledSqlQuery } from "../types";
|
|
2
|
+
export declare function compileSqlTemplate(templates: TemplateStringsArray, args: unknown[], argOffset?: number): CompiledSqlQuery;
|
|
3
3
|
//# sourceMappingURL=template-compiler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-compiler.d.ts","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"template-compiler.d.ts","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,gBAAgB,EAAoB,MAAM,UAAU,CAAA;AAInF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,SAAS,SAAI,GAAG,gBAAgB,CAoCpH"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Clause } from "../clauses/abstract.clause";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const cache = new WeakMap();
|
|
3
|
+
export function compileSqlTemplate(templates, args, argOffset = 0) {
|
|
4
|
+
const cached = cache.get(templates);
|
|
5
|
+
if (cached)
|
|
6
|
+
return { args: args.map(prepareValue), text: cached };
|
|
7
|
+
const templateLength = templates.length;
|
|
4
8
|
const query = {
|
|
5
|
-
text:
|
|
9
|
+
text: '',
|
|
6
10
|
args: [],
|
|
7
11
|
};
|
|
8
|
-
|
|
9
|
-
query.text
|
|
12
|
+
templates.forEach((template, index) => {
|
|
13
|
+
query.text += template;
|
|
10
14
|
if (index === templateLength - 1)
|
|
11
15
|
return;
|
|
12
|
-
const value =
|
|
16
|
+
const value = args[index];
|
|
13
17
|
if (value instanceof Clause) {
|
|
14
18
|
value.mapIntoQuery(query);
|
|
15
19
|
}
|
|
@@ -19,10 +23,11 @@ export function compileSqlTemplate(params, argOffset = 0) {
|
|
|
19
23
|
Use null if you want NULL in SQL, or ensure the value is defined.`);
|
|
20
24
|
}
|
|
21
25
|
query.args.push(value);
|
|
22
|
-
query.text
|
|
26
|
+
query.text += `$${query.args.length + argOffset}`;
|
|
23
27
|
}
|
|
24
28
|
});
|
|
25
|
-
|
|
29
|
+
!args.some(value => value instanceof Clause) && cache.set(templates, query.text);
|
|
30
|
+
return { args: query.args.map(prepareValue), text: query.text };
|
|
26
31
|
}
|
|
27
32
|
const prepareValue = (value) => {
|
|
28
33
|
if (value === null || value === undefined) {
|
|
@@ -32,6 +37,9 @@ const prepareValue = (value) => {
|
|
|
32
37
|
if (value instanceof Date) {
|
|
33
38
|
return value.toISOString();
|
|
34
39
|
}
|
|
40
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
41
|
+
return '\\x' + Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString('hex');
|
|
42
|
+
}
|
|
35
43
|
if (Array.isArray(value)) {
|
|
36
44
|
const elements = value.map(el => {
|
|
37
45
|
if (el === null || el === undefined)
|
|
@@ -51,7 +59,7 @@ const prepareValue = (value) => {
|
|
|
51
59
|
}
|
|
52
60
|
return prepareObject(value);
|
|
53
61
|
}
|
|
54
|
-
return value
|
|
62
|
+
return String(value);
|
|
55
63
|
};
|
|
56
64
|
const prepareObject = (obj) => {
|
|
57
65
|
if (obj && typeof obj.toPG === 'function') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m2k-5f/pgtx",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Blazing-fast PostgreSQL driver with pipeline support.",
|
|
6
6
|
"files": [
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git://github.com/
|
|
19
|
+
"url": "git://github.com/M2Kc-s4/pgtx.git"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"sql",
|
|
23
23
|
"postgres",
|
|
24
|
+
"blazing",
|
|
25
|
+
"stream",
|
|
24
26
|
"driver",
|
|
25
27
|
"pipeline",
|
|
26
28
|
"query-builder",
|
|
@@ -28,11 +30,11 @@
|
|
|
28
30
|
"transactions",
|
|
29
31
|
"prepared-statements"
|
|
30
32
|
],
|
|
31
|
-
"author": "
|
|
33
|
+
"author": "M2Kc-s4",
|
|
32
34
|
"license": "MIT",
|
|
33
|
-
"homepage": "https://github.com/
|
|
35
|
+
"homepage": "https://github.com/M2Kc-s4/pgtx",
|
|
34
36
|
"bugs": {
|
|
35
|
-
"url": "https://github.com/
|
|
37
|
+
"url": "https://github.com/M2Kc-s4/pgtx/issues"
|
|
36
38
|
},
|
|
37
39
|
"exports": {
|
|
38
40
|
".": {
|
|
@@ -44,6 +46,7 @@
|
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/node": "^26.2.0",
|
|
46
48
|
"mitata": "^1.0.34",
|
|
49
|
+
"pg": "^8.23.0",
|
|
47
50
|
"postgres": "^3.4.9",
|
|
48
51
|
"tsx": "^4.23.11",
|
|
49
52
|
"typescript": "^5.9.3"
|