@m2k-5f/pgtx 2.2.0 → 2.3.1
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 +372 -307
- package/dist/clauses/abstract.clause.js +1 -5
- package/dist/clauses/array.clause.js +3 -7
- package/dist/clauses/empty.clause.js +3 -7
- package/dist/clauses/exclude.clause.js +2 -6
- package/dist/clauses/fragment.clause.js +4 -8
- package/dist/clauses/iden.caluse.js +2 -6
- package/dist/clauses/index.js +9 -25
- package/dist/clauses/insert.clause.js +2 -6
- package/dist/clauses/literal.clause.js +2 -6
- package/dist/clauses/update.clause.js +2 -6
- package/dist/clauses/where.clause.js +2 -6
- package/dist/connection.d.ts +11 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +108 -111
- package/dist/error.d.ts +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -6
- package/dist/index.js +24 -37
- package/dist/pool.d.ts +9 -7
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +29 -42
- package/dist/protocol/connection-request-writer.js +13 -18
- package/dist/protocol/connection-response-reader.js +4 -9
- package/dist/protocol/constants.js +4 -7
- package/dist/protocol/socket-authorization.d.ts +5 -1
- package/dist/protocol/socket-authorization.d.ts.map +1 -1
- package/dist/protocol/socket-authorization.js +38 -34
- package/dist/protocol/socket-connector.js +3 -7
- package/dist/query.js +2 -6
- package/dist/queue.js +1 -5
- package/dist/security/md5.js +4 -8
- package/dist/security/sasl.js +7 -11
- package/dist/transaction.d.ts +7 -5
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +18 -26
- package/dist/types.js +0 -2
- package/dist/utils/template-compiler.js +3 -6
- package/dist/utils/value-parser.js +2 -7
- package/package.json +9 -2
package/dist/transaction.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Future } from "fluent-future";
|
|
1
2
|
import { Connection } from "./connection";
|
|
3
|
+
import { PostgresError } from "./error";
|
|
2
4
|
/**
|
|
3
5
|
* Represents an active SQL transaction.
|
|
4
6
|
* All queries are executed on a single dedicated connection.
|
|
@@ -15,15 +17,15 @@ export declare class Transaction {
|
|
|
15
17
|
/**
|
|
16
18
|
* Commits the current transaction.
|
|
17
19
|
*/
|
|
18
|
-
commit():
|
|
20
|
+
commit(): Future<[], PostgresError>;
|
|
19
21
|
/**
|
|
20
22
|
* Rolls back the current transaction.
|
|
21
23
|
*/
|
|
22
|
-
rollback():
|
|
24
|
+
rollback(): Future<[], PostgresError>;
|
|
23
25
|
/**
|
|
24
26
|
* Executes a query within the current transaction.
|
|
25
27
|
*/
|
|
26
|
-
query<T extends Record<string, any>>(strings: TemplateStringsArray, ...values: any[]):
|
|
28
|
+
query<T extends Record<string, any>>(strings: TemplateStringsArray, ...values: any[]): Future<T[], PostgresError>;
|
|
27
29
|
/**
|
|
28
30
|
* Creates a sub-transaction using PostgreSQL SAVEPOINT.
|
|
29
31
|
* If the callback throws, only the actions within this savepoint are rolled back.
|
|
@@ -31,9 +33,9 @@ export declare class Transaction {
|
|
|
31
33
|
* @example
|
|
32
34
|
* await tx.savepoint('my_point', async (stx) => {
|
|
33
35
|
* await stx.query`INSERT ...`;
|
|
34
|
-
* if (error) throw new Error()
|
|
36
|
+
* if (error) throw new Error() // Only this insert rolls back
|
|
35
37
|
* });
|
|
36
38
|
*/
|
|
37
|
-
savepoint(name: string, callback: (tx: Transaction) => Promise<
|
|
39
|
+
savepoint<T>(name: string, callback: (tx: Transaction) => Promise<T>): Future<T, Error>;
|
|
38
40
|
}
|
|
39
41
|
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"
|
|
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,IAIiC,MAAM,CAAC,EAAE,EAAE,aAAa,CAAC;IAGvE;;OAEG;IACI,QAAQ,IAI+B,MAAM,CAAC,EAAE,EAAE,aAAa,CAAC;IAGvE;;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
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Transaction = void 0;
|
|
4
|
-
const clauses_1 = require("./clauses");
|
|
1
|
+
import { Begin, Future } from "fluent-future";
|
|
2
|
+
import { IdentifierClause } from "./clauses";
|
|
5
3
|
/**
|
|
6
4
|
* Represents an active SQL transaction.
|
|
7
5
|
* All queries are executed on a single dedicated connection.
|
|
8
6
|
*/
|
|
9
|
-
class Transaction {
|
|
7
|
+
export class Transaction {
|
|
10
8
|
constructor(conn) {
|
|
11
9
|
this.conn = conn;
|
|
12
10
|
this.isFinished = false;
|
|
@@ -25,25 +23,25 @@ class Transaction {
|
|
|
25
23
|
/**
|
|
26
24
|
* Commits the current transaction.
|
|
27
25
|
*/
|
|
28
|
-
|
|
26
|
+
commit() {
|
|
29
27
|
this.checkActive();
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
return this.conn.query `COMMIT`
|
|
29
|
+
.tap(() => this.isFinished = true);
|
|
32
30
|
}
|
|
33
31
|
/**
|
|
34
32
|
* Rolls back the current transaction.
|
|
35
33
|
*/
|
|
36
|
-
|
|
34
|
+
rollback() {
|
|
37
35
|
this.checkActive();
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
return this.conn.query `ROLLBACK`
|
|
37
|
+
.tap(() => this.isFinished = true);
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
40
|
* Executes a query within the current transaction.
|
|
43
41
|
*/
|
|
44
|
-
|
|
42
|
+
query(strings, ...values) {
|
|
45
43
|
this.checkActive();
|
|
46
|
-
return
|
|
44
|
+
return this.conn.query(strings, ...values);
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
47
|
* Creates a sub-transaction using PostgreSQL SAVEPOINT.
|
|
@@ -52,21 +50,15 @@ class Transaction {
|
|
|
52
50
|
* @example
|
|
53
51
|
* await tx.savepoint('my_point', async (stx) => {
|
|
54
52
|
* await stx.query`INSERT ...`;
|
|
55
|
-
* if (error) throw new Error()
|
|
53
|
+
* if (error) throw new Error() // Only this insert rolls back
|
|
56
54
|
* });
|
|
57
55
|
*/
|
|
58
|
-
|
|
56
|
+
savepoint(name, callback) {
|
|
59
57
|
this.checkActive();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
await this.conn.query `ROLLBACK TO SAVEPOINT ${clauses_1.IdentifierClause.create(name)}`;
|
|
68
|
-
return err instanceof Error ? err : new Error(String(err));
|
|
69
|
-
}
|
|
58
|
+
return Begin()
|
|
59
|
+
.andThen(() => this.conn.query `SAVEPOINT ${IdentifierClause.create(name)}`)
|
|
60
|
+
.andThen(() => Future.of(callback(this))
|
|
61
|
+
.tap(() => this.conn.query `RELEASE SAVEPOINT ${IdentifierClause.create(name)}`)
|
|
62
|
+
.tapErr(() => this.conn.query `ROLLBACK TO SAVEPOINT ${IdentifierClause.create(name)}`));
|
|
70
63
|
}
|
|
71
64
|
}
|
|
72
|
-
exports.Transaction = Transaction;
|
package/dist/types.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.compileSqlTemplate = compileSqlTemplate;
|
|
4
|
-
const abstract_clause_1 = require("../clauses/abstract.clause");
|
|
5
|
-
function compileSqlTemplate(params, argOffset = 0) {
|
|
1
|
+
import { Clause } from "../clauses/abstract.clause";
|
|
2
|
+
export function compileSqlTemplate(params, argOffset = 0) {
|
|
6
3
|
const templateLength = params.templates.length;
|
|
7
4
|
const query = {
|
|
8
5
|
text: [],
|
|
@@ -13,7 +10,7 @@ function compileSqlTemplate(params, argOffset = 0) {
|
|
|
13
10
|
if (index === templateLength - 1)
|
|
14
11
|
return;
|
|
15
12
|
const value = params.args[index];
|
|
16
|
-
if (value instanceof
|
|
13
|
+
if (value instanceof Clause) {
|
|
17
14
|
value.mapIntoQuery(query);
|
|
18
15
|
}
|
|
19
16
|
else {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setTypeParser = void 0;
|
|
4
|
-
exports.parseRowValues = parseRowValues;
|
|
5
1
|
const parsePostgresArray = (v) => {
|
|
6
2
|
if (v === '{}')
|
|
7
3
|
return [];
|
|
@@ -70,7 +66,7 @@ const Parsers = {
|
|
|
70
66
|
3807: (v) => parsePostgresArray(v).map(el => JSON.parse(el)), // jsonb[]
|
|
71
67
|
};
|
|
72
68
|
const defaultParser = (v) => v;
|
|
73
|
-
function parseRowValues(columns, rows) {
|
|
69
|
+
export function parseRowValues(columns, rows) {
|
|
74
70
|
const result = [];
|
|
75
71
|
const columnsLength = columns.length;
|
|
76
72
|
const columnParsers = columns.map(col => Parsers[col.typeOID] || defaultParser);
|
|
@@ -95,7 +91,6 @@ function parseRowValues(columns, rows) {
|
|
|
95
91
|
}
|
|
96
92
|
return result;
|
|
97
93
|
}
|
|
98
|
-
const setTypeParser = (typeOID, parser) => {
|
|
94
|
+
export const setTypeParser = (typeOID, parser) => {
|
|
99
95
|
Parsers[typeOID] = parser;
|
|
100
96
|
};
|
|
101
|
-
exports.setTypeParser = setTypeParser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m2k-5f/pgtx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Blazing-fast PostgreSQL driver with pipeline support.",
|
|
5
6
|
"files": [
|
|
6
7
|
"dist",
|
|
@@ -10,7 +11,8 @@
|
|
|
10
11
|
"build": "tsc",
|
|
11
12
|
"prepublishOnly": "npm run build",
|
|
12
13
|
"testGitHub": "node --import tsx --test $(find tests -name '*.test.ts')",
|
|
13
|
-
"test": "node --import tsx --test ./tests/*.test.ts"
|
|
14
|
+
"test": "node --import tsx --test ./tests/*.test.ts",
|
|
15
|
+
"benchmark": "npx tsx benchmark.ts"
|
|
14
16
|
},
|
|
15
17
|
"repository": {
|
|
16
18
|
"type": "git",
|
|
@@ -41,8 +43,13 @@
|
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@types/node": "^26.1.1",
|
|
46
|
+
"mitata": "^1.0.34",
|
|
44
47
|
"pg": "^8.22.0",
|
|
48
|
+
"postgres": "^3.4.9",
|
|
45
49
|
"tsx": "^4.21.0",
|
|
46
50
|
"typescript": "^5.0.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"fluent-future": "^1.3.2"
|
|
47
54
|
}
|
|
48
55
|
}
|