@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/query.js
CHANGED
|
@@ -1,57 +1,56 @@
|
|
|
1
|
-
import { Future } from "fluent-future";
|
|
2
1
|
import { ErrQueryTimeout } from "./error";
|
|
3
2
|
export class Query {
|
|
4
|
-
constructor(
|
|
5
|
-
this.statement = statement;
|
|
6
|
-
this.text = text;
|
|
7
|
-
this.args = args;
|
|
3
|
+
constructor(timeout) {
|
|
8
4
|
this._timer = setTimeout(() => {
|
|
9
|
-
this.
|
|
5
|
+
this.error(ErrQueryTimeout);
|
|
10
6
|
}, timeout);
|
|
11
7
|
}
|
|
12
8
|
}
|
|
13
9
|
export class CollectQuery extends Query {
|
|
14
|
-
constructor(
|
|
15
|
-
super(
|
|
10
|
+
constructor(meta, text, args, columns, resolvers, timeout) {
|
|
11
|
+
super(timeout);
|
|
12
|
+
this.meta = meta;
|
|
13
|
+
this.text = text;
|
|
14
|
+
this.args = args;
|
|
16
15
|
this.columns = columns;
|
|
16
|
+
this.resolvers = resolvers;
|
|
17
17
|
this._rows = [];
|
|
18
|
-
const { future, reject, resolve } = Future.withResolvers();
|
|
19
|
-
this.future = future;
|
|
20
|
-
this._resolve = resolve;
|
|
21
|
-
this._reject = reject;
|
|
22
18
|
}
|
|
23
19
|
push(value) {
|
|
24
20
|
this._rows.push(value);
|
|
25
21
|
}
|
|
26
|
-
|
|
22
|
+
error(cause) {
|
|
27
23
|
clearTimeout(this._timer);
|
|
28
|
-
this.
|
|
24
|
+
this.resolvers.reject(cause);
|
|
29
25
|
}
|
|
30
|
-
|
|
26
|
+
complete() {
|
|
31
27
|
clearTimeout(this._timer);
|
|
32
|
-
this.
|
|
28
|
+
this.resolvers.resolve(this._rows);
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
31
|
export class ExecuteQuery extends Query {
|
|
36
|
-
constructor(
|
|
37
|
-
super(
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
32
|
+
constructor(meta, text, args, resolvers, timeout) {
|
|
33
|
+
super(timeout);
|
|
34
|
+
this.meta = meta;
|
|
35
|
+
this.text = text;
|
|
36
|
+
this.args = args;
|
|
37
|
+
this.resolvers = resolvers;
|
|
42
38
|
}
|
|
43
|
-
|
|
39
|
+
error(cause) {
|
|
44
40
|
clearTimeout(this._timer);
|
|
45
|
-
this.
|
|
41
|
+
this.resolvers.reject(cause);
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
complete() {
|
|
48
44
|
clearTimeout(this._timer);
|
|
49
|
-
this.
|
|
45
|
+
this.resolvers.resolve();
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
export class StreamQuery extends Query {
|
|
53
|
-
constructor(
|
|
54
|
-
super(
|
|
49
|
+
constructor(meta, text, args, controller, columns, timeout) {
|
|
50
|
+
super(timeout);
|
|
51
|
+
this.meta = meta;
|
|
52
|
+
this.text = text;
|
|
53
|
+
this.args = args;
|
|
55
54
|
this.controller = controller;
|
|
56
55
|
this.columns = columns;
|
|
57
56
|
}
|
|
@@ -61,11 +60,11 @@ export class StreamQuery extends Query {
|
|
|
61
60
|
}
|
|
62
61
|
catch { }
|
|
63
62
|
}
|
|
64
|
-
|
|
63
|
+
error(cause) {
|
|
65
64
|
clearTimeout(this._timer);
|
|
66
65
|
this.controller.error(cause);
|
|
67
66
|
}
|
|
68
|
-
|
|
67
|
+
complete() {
|
|
69
68
|
clearTimeout(this._timer);
|
|
70
69
|
try {
|
|
71
70
|
this.controller.close();
|
|
@@ -73,3 +72,19 @@ export class StreamQuery extends Query {
|
|
|
73
72
|
catch { }
|
|
74
73
|
}
|
|
75
74
|
}
|
|
75
|
+
export class ParseQuery extends Query {
|
|
76
|
+
constructor(meta, text, resolvers, timeout) {
|
|
77
|
+
super(timeout);
|
|
78
|
+
this.meta = meta;
|
|
79
|
+
this.text = text;
|
|
80
|
+
this.resolvers = resolvers;
|
|
81
|
+
}
|
|
82
|
+
error(cause) {
|
|
83
|
+
clearTimeout(this._timer);
|
|
84
|
+
this.resolvers.reject(cause);
|
|
85
|
+
}
|
|
86
|
+
complete() {
|
|
87
|
+
clearTimeout(this._timer);
|
|
88
|
+
this.resolvers.resolve(this.meta);
|
|
89
|
+
}
|
|
90
|
+
}
|
package/dist/queue.d.ts
CHANGED
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;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;
|
|
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;IAEzD,IAAI,QAAQ,QAA4C;CAC3D;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
|
@@ -30,6 +30,7 @@ export class Queue {
|
|
|
30
30
|
return this._pointer < this._queue.length;
|
|
31
31
|
}
|
|
32
32
|
get isFree() { return this._pointer >= this._queue.length; }
|
|
33
|
+
get residual() { return this._queue.slice(this._pointer); }
|
|
33
34
|
}
|
|
34
35
|
export class RingQueue {
|
|
35
36
|
constructor(requestedCapacity = 20000) {
|
package/dist/types.d.ts
CHANGED
|
@@ -49,9 +49,11 @@ export type ConnectionConfig = {
|
|
|
49
49
|
export type StatementName = Branded<string, 'StatementName'>;
|
|
50
50
|
export type QueryText = Branded<string, 'QueryText'>;
|
|
51
51
|
export type ChannelName = Branded<string, "ChannelName">;
|
|
52
|
-
export type
|
|
52
|
+
export type ParameterDescription = DataTypeOid[];
|
|
53
|
+
export type StatementMeta = {
|
|
53
54
|
statement: StatementName;
|
|
54
55
|
columns: ColumnDescription[];
|
|
56
|
+
parameters: ParameterDescription;
|
|
55
57
|
};
|
|
56
58
|
export type PoolPartialConfig = ConnectionPartialConfig & {
|
|
57
59
|
max?: number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,MAAM,MAAM,OAA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
export declare function compileSqlTemplate(templates: TemplateStringsArray, args: unknown[], argOffset?: number):
|
|
1
|
+
import { QueryText } from "../types";
|
|
2
|
+
export declare function compileSqlTemplate(templates: TemplateStringsArray, args: unknown[], argOffset?: number): {
|
|
3
|
+
args: (string | null)[];
|
|
4
|
+
text: QueryText;
|
|
5
|
+
};
|
|
3
6
|
//# 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,
|
|
1
|
+
{"version":3,"file":"template-compiler.d.ts","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"AACA,OAAO,EAA0C,SAAS,EAAE,MAAM,UAAU,CAAA;AAI5E,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,SAAS,SAAI;;UAG5B,SAAS;EAqC9E"}
|
|
@@ -27,7 +27,10 @@ export function compileSqlTemplate(templates, args, argOffset = 0) {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
!args.some(value => value instanceof Clause) && cache.set(templates, query.text);
|
|
30
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
args: query.args.map(prepareValue),
|
|
32
|
+
text: query.text
|
|
33
|
+
};
|
|
31
34
|
}
|
|
32
35
|
const prepareValue = (value) => {
|
|
33
36
|
if (value === null || value === undefined) {
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QueryText } from "./types";
|
|
2
|
+
export declare function compileSqlTemplate(templates: TemplateStringsArray, args: unknown[], argOffset?: number): {
|
|
3
|
+
args: unknown[];
|
|
4
|
+
text: QueryText;
|
|
5
|
+
};
|
|
6
|
+
export declare function prepareObject(obj: any): string;
|
|
7
|
+
export declare function prepareValue(value: unknown): string | null;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAA0C,SAAS,EAAE,MAAM,SAAS,CAAA;AAI3E,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,SAAS,SAAI;;UAGpD,SAAS;EAkCtD;AAGD,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAM9C;AAGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CA0C1D"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Clause } from "./clauses/abstract.clause";
|
|
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, text: cached };
|
|
7
|
+
const templateLength = templates.length;
|
|
8
|
+
const query = {
|
|
9
|
+
text: '',
|
|
10
|
+
args: [],
|
|
11
|
+
};
|
|
12
|
+
templates.forEach((template, index) => {
|
|
13
|
+
query.text += template;
|
|
14
|
+
if (index === templateLength - 1)
|
|
15
|
+
return;
|
|
16
|
+
const value = args[index];
|
|
17
|
+
if (value instanceof Clause) {
|
|
18
|
+
value.mapIntoQuery(query);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
throw new TypeError(`Query parameter at position ${query.args.length + argOffset + 1} is undefined.
|
|
23
|
+
Use null if you want NULL in SQL, or ensure the value is defined.`);
|
|
24
|
+
}
|
|
25
|
+
query.args.push(value);
|
|
26
|
+
query.text += `$${query.args.length + argOffset}`;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
!args.some(value => value instanceof Clause) && cache.set(templates, query.text);
|
|
30
|
+
return query;
|
|
31
|
+
}
|
|
32
|
+
export function prepareObject(obj) {
|
|
33
|
+
if (obj && typeof obj.toPG === "function") {
|
|
34
|
+
return JSON.stringify(obj.toPG());
|
|
35
|
+
}
|
|
36
|
+
return JSON.stringify(obj);
|
|
37
|
+
}
|
|
38
|
+
export function prepareValue(value) {
|
|
39
|
+
if (value === null || value === undefined) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "object") {
|
|
43
|
+
if (value instanceof Date) {
|
|
44
|
+
return value.toISOString();
|
|
45
|
+
}
|
|
46
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
47
|
+
return "\\x" + Buffer
|
|
48
|
+
.from(value.buffer, value.byteOffset, value.byteLength)
|
|
49
|
+
.toString("hex");
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
const elements = value.map(el => {
|
|
53
|
+
if (el === null || el === undefined)
|
|
54
|
+
return "NULL";
|
|
55
|
+
if (typeof el === "boolean")
|
|
56
|
+
return el ? "true" : "false";
|
|
57
|
+
if (typeof el === "object") {
|
|
58
|
+
const res = prepareValue(el);
|
|
59
|
+
return `"${res?.replace(/"/g, '\\"')}"`;
|
|
60
|
+
}
|
|
61
|
+
if (typeof el === "string") {
|
|
62
|
+
return `"${el
|
|
63
|
+
.replace(/\\/g, "\\\\")
|
|
64
|
+
.replace(/"/g, '\\"')}"`;
|
|
65
|
+
}
|
|
66
|
+
return String(el);
|
|
67
|
+
});
|
|
68
|
+
return `{${elements.join(",")}}`;
|
|
69
|
+
}
|
|
70
|
+
return prepareObject(value);
|
|
71
|
+
}
|
|
72
|
+
return String(value);
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m2k-5f/pgtx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Blazing-fast PostgreSQL driver with pipeline support.",
|
|
6
6
|
"files": [
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"testGitHub": "node --import tsx --test $(find tests -name '*.test.ts')",
|
|
14
|
-
"test": "node --import tsx --test ./tests/*.test.ts",
|
|
14
|
+
"test": "node --env-file=.env --import tsx --test ./tests/*.test.ts",
|
|
15
15
|
"benchmark": "npx tsx benchmark.ts"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|