@contember/database 1.0.0-alpha.8 → 1.0.0-rc.10
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/src/client/Client.d.ts +2 -2
- package/dist/src/client/Client.d.ts.map +1 -1
- package/dist/src/client/Client.js +10 -7
- package/dist/src/client/Client.js.map +1 -1
- package/dist/src/client/Connection.d.ts +8 -3
- package/dist/src/client/Connection.d.ts.map +1 -1
- package/dist/src/client/Connection.js +7 -6
- package/dist/src/client/Connection.js.map +1 -1
- package/dist/src/client/EventManager.d.ts +2 -5
- package/dist/src/client/EventManager.d.ts.map +1 -1
- package/dist/src/client/EventManager.js +3 -4
- package/dist/src/client/EventManager.js.map +1 -1
- package/dist/src/client/SingleConnection.d.ts +3 -1
- package/dist/src/client/SingleConnection.d.ts.map +1 -1
- package/dist/src/client/SingleConnection.js +7 -5
- package/dist/src/client/SingleConnection.js.map +1 -1
- package/dist/src/client/Transaction.d.ts +3 -1
- package/dist/src/client/Transaction.d.ts.map +1 -1
- package/dist/src/client/Transaction.js +11 -8
- package/dist/src/client/Transaction.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/utils/ConstraintHelper.d.ts.map +1 -1
- package/dist/src/utils/ConstraintHelper.js +6 -0
- package/dist/src/utils/ConstraintHelper.js.map +1 -1
- package/dist/tests/cases/unit/eventManagerTest.d.ts +2 -0
- package/dist/tests/cases/unit/eventManagerTest.d.ts.map +1 -0
- package/dist/tests/cases/unit/eventManagerTest.js +62 -0
- package/dist/tests/cases/unit/eventManagerTest.js.map +1 -0
- package/dist/tests/cases/unit/queryBuilderTest.js +1 -1
- package/dist/tests/cases/unit/queryBuilderTest.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/client/Client.ts +22 -8
- package/src/client/Connection.ts +12 -7
- package/src/client/EventManager.ts +4 -3
- package/src/client/SingleConnection.ts +14 -9
- package/src/client/Transaction.ts +13 -7
- package/src/utils/ConstraintHelper.ts +7 -1
- package/tests/cases/unit/eventManagerTest.ts +63 -0
- package/tests/cases/unit/queryBuilderTest.ts +2 -2
|
@@ -7,8 +7,8 @@ declare class Client<ConnectionType extends Connection.ConnectionLike = Connecti
|
|
|
7
7
|
readonly connection: ConnectionType;
|
|
8
8
|
readonly schema: string;
|
|
9
9
|
readonly queryMeta: Record<string, any>;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
readonly eventManager: EventManager;
|
|
11
|
+
constructor(connection: ConnectionType, schema: string, queryMeta: Record<string, any>, eventManager?: EventManager);
|
|
12
12
|
forSchema(schema: string): Client<ConnectionType>;
|
|
13
13
|
transaction<T>(transactionScope: (wrapper: Client<Connection.TransactionLike>) => Promise<T> | T): Promise<T>;
|
|
14
14
|
selectBuilder<Result = SelectBuilder.Result>(): SelectBuilder<Result>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../../src/client/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,cAAM,MAAM,CAAC,cAAc,SAAS,UAAU,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAE,YAAW,UAAU,CAAC,SAAS;aAExG,UAAU,EAAE,cAAc;aAC1B,MAAM,EAAE,MAAM;aACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../../src/client/Client.ts"],"names":[],"mappings":"AAAA,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AU,GAAE,SAAS,GAAG,EAAO,EAC/B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAC9B,MAAM,GAAE,UAAU,CAAC,WAAgB,GACjC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAYlC,kBAAkB,IAAI,YAAY,CAAC,iBAAiB,CAAC;CAUrD;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Client = void 0;
|
|
4
4
|
const builders_1 = require("../builders");
|
|
5
5
|
const queryable_1 = require("../queryable");
|
|
6
|
+
const EventManager_1 = require("./EventManager");
|
|
6
7
|
const queryable_2 = require("@contember/queryable");
|
|
7
8
|
class Client {
|
|
8
|
-
constructor(connection, schema, queryMeta) {
|
|
9
|
+
constructor(connection, schema, queryMeta, eventManager = new EventManager_1.EventManager(connection.eventManager)) {
|
|
9
10
|
this.connection = connection;
|
|
10
11
|
this.schema = schema;
|
|
11
12
|
this.queryMeta = queryMeta;
|
|
12
|
-
|
|
13
|
-
get eventManager() {
|
|
14
|
-
return this.connection.eventManager;
|
|
13
|
+
this.eventManager = eventManager;
|
|
15
14
|
}
|
|
16
15
|
forSchema(schema) {
|
|
17
|
-
|
|
16
|
+
const eventManager = new EventManager_1.EventManager(this.eventManager.parent);
|
|
17
|
+
return new Client(this.connection, schema, this.queryMeta, eventManager);
|
|
18
18
|
}
|
|
19
19
|
async transaction(transactionScope) {
|
|
20
|
-
return await this.connection.transaction(
|
|
20
|
+
return await this.connection.transaction(transaction => transactionScope(new Client(transaction, this.schema, this.queryMeta, new EventManager_1.EventManager(transaction.eventManager))), { eventManager: this.eventManager });
|
|
21
21
|
}
|
|
22
22
|
selectBuilder() {
|
|
23
23
|
return builders_1.SelectBuilder.create();
|
|
@@ -32,7 +32,10 @@ class Client {
|
|
|
32
32
|
return builders_1.DeleteBuilder.create();
|
|
33
33
|
}
|
|
34
34
|
async query(sql, parameters = [], meta = {}, config = {}) {
|
|
35
|
-
return this.connection.query(sql, parameters, { ...this.queryMeta, ...meta },
|
|
35
|
+
return this.connection.query(sql, parameters, { ...this.queryMeta, ...meta }, {
|
|
36
|
+
eventManager: this.eventManager,
|
|
37
|
+
...config,
|
|
38
|
+
});
|
|
36
39
|
}
|
|
37
40
|
createQueryHandler() {
|
|
38
41
|
const handler = new queryable_2.QueryHandler(new queryable_1.DatabaseQueryable(this, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../src/client/Client.ts"],"names":[],"mappings":";;;AAAA,0CAAwF;AACxF,4CAAgD;
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../src/client/Client.ts"],"names":[],"mappings":";;;AAAA,0CAAwF;AACxF,4CAAgD;AAEhD,iDAA6C;AAC7C,oDAAmD;AAEnD,MAAM,MAAM;IACX,YACiB,UAA0B,EAC1B,MAAc,EACd,SAA8B,EAC9B,eAA6B,IAAI,2BAAY,CAAC,UAAU,CAAC,YAAY,CAAC;QAHtE,eAAU,GAAV,UAAU,CAAgB;QAC1B,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAqB;QAC9B,iBAAY,GAAZ,YAAY,CAA0D;IACpF,CAAC;IAEG,SAAS,CAAC,MAAc;QAC9B,MAAM,YAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAC/D,OAAO,IAAI,MAAM,CAAiB,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;IACzF,CAAC;IAED,KAAK,CAAC,WAAW,CAAI,gBAAiF;QACrG,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CACvC,WAAW,CAAC,EAAE,CACb,gBAAgB,CACf,IAAI,MAAM,CACT,WAAW,EACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,SAAS,EACd,IAAI,2BAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAC1C,CAAC,EACJ,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,CACnC,CAAA;IACF,CAAC;IAED,aAAa;QACZ,OAAO,wBAAa,CAAC,MAAM,EAAU,CAAA;IACtC,CAAC;IAED,aAAa;QACZ,OAAO,wBAAa,CAAC,MAAM,EAAE,CAAA;IAC9B,CAAC;IAED,aAAa;QACZ,OAAO,wBAAa,CAAC,MAAM,EAAE,CAAA;IAC9B,CAAC;IAED,aAAa;QACZ,OAAO,wBAAa,CAAC,MAAM,EAAE,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,KAAK,CACV,GAAW,EACX,aAA6B,EAAE,EAC/B,OAA4B,EAAE,EAC9B,SAAiC,EAAE;QAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAC3B,GAAG,EACH,UAAU,EACV,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,EAAE,EAC9B;YACC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,GAAG,MAAM;SACT,CACD,CAAA;IACF,CAAC;IAED,kBAAkB;QACjB,MAAM,OAAO,GAAG,IAAI,wBAAY,CAC/B,IAAI,6BAAiB,CAAC,IAAI,EAAE;YAC3B,GAAG;gBACF,OAAO,OAAO,CAAA;YACf,CAAC;SACD,CAAC,CACF,CAAA;QACD,OAAO,OAAO,CAAA;IACf,CAAC;CACD;AAEQ,wBAAM"}
|
|
@@ -8,21 +8,26 @@ declare class Connection implements Connection.ConnectionLike, Connection.Client
|
|
|
8
8
|
private readonly pool;
|
|
9
9
|
constructor(config: PoolConfig, queryConfig: Connection.QueryConfig, eventManager?: EventManager);
|
|
10
10
|
createClient(schema: string, queryMeta: Record<string, any>): Client;
|
|
11
|
-
transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result
|
|
11
|
+
transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result, options?: {
|
|
12
|
+
eventManager?: EventManager;
|
|
13
|
+
}): Promise<Result>;
|
|
12
14
|
end(): Promise<void>;
|
|
13
|
-
query<Row extends Record<string, any>>(sql: string, parameters?: any[], meta?: Record<string, any>, config?: Connection.QueryConfig): Promise<Connection.Result<Row>>;
|
|
15
|
+
query<Row extends Record<string, any>>(sql: string, parameters?: any[], meta?: Record<string, any>, { eventManager, ...config }?: Connection.QueryConfig): Promise<Connection.Result<Row>>;
|
|
14
16
|
getPoolStatus(): Connection.PoolStatus;
|
|
15
17
|
}
|
|
16
18
|
declare namespace Connection {
|
|
17
19
|
interface QueryConfig {
|
|
18
20
|
timing?: boolean;
|
|
21
|
+
eventManager?: EventManager;
|
|
19
22
|
}
|
|
20
23
|
interface Queryable {
|
|
21
24
|
readonly eventManager: EventManager;
|
|
22
25
|
query<Row extends Record<string, any>>(sql: string, parameters?: readonly any[], meta?: Record<string, any>, config?: Connection.QueryConfig): Promise<Connection.Result<Row>>;
|
|
23
26
|
}
|
|
24
27
|
interface Transactional {
|
|
25
|
-
transaction<Result>(trx: (connection: TransactionLike) => Promise<Result> | Result
|
|
28
|
+
transaction<Result>(trx: (connection: TransactionLike) => Promise<Result> | Result, options?: {
|
|
29
|
+
eventManager?: EventManager;
|
|
30
|
+
}): Promise<Result>;
|
|
26
31
|
}
|
|
27
32
|
interface ConnectionLike extends Transactional, Queryable {
|
|
28
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.d.ts","sourceRoot":"","sources":["../../../src/client/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,IAAI,CAAA;AACrC,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"Connection.d.ts","sourceRoot":"","sources":["../../../src/client/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,IAAI,CAAA;AACrC,OAAO,EAAE,YAAY,E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AAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAClC;IAED,KAAY,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC,CAAA;IAE9F,UAAiB,MAAM,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;QAC5E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;QACzB,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,CAAA;QACpB,QAAQ,CAAC,MAAM,CAAC,EAAE;YACjB,aAAa,EAAE,MAAM,CAAA;YACrB,YAAY,EAAE,MAAM,CAAA;SACpB,CAAA;KACD;IAEM,MAAM,eAAe,oDAAoD,CAAA;IAEhF,KAAY,UAAU,GAAG;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1G;AAED,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -7,7 +7,7 @@ const Client_1 = require("./Client");
|
|
|
7
7
|
const Transaction_1 = require("./Transaction");
|
|
8
8
|
const execution_1 = require("./execution");
|
|
9
9
|
class Connection {
|
|
10
|
-
constructor(config, queryConfig, eventManager = new EventManager_1.
|
|
10
|
+
constructor(config, queryConfig, eventManager = new EventManager_1.EventManager(null)) {
|
|
11
11
|
this.config = config;
|
|
12
12
|
this.queryConfig = queryConfig;
|
|
13
13
|
this.eventManager = eventManager;
|
|
@@ -19,11 +19,12 @@ class Connection {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
createClient(schema, queryMeta) {
|
|
22
|
-
return new Client_1.Client(this, schema, queryMeta);
|
|
22
|
+
return new Client_1.Client(this, schema, queryMeta, new EventManager_1.EventManager(this.eventManager));
|
|
23
23
|
}
|
|
24
|
-
async transaction(callback) {
|
|
24
|
+
async transaction(callback, options = {}) {
|
|
25
|
+
var _a;
|
|
25
26
|
const client = await (0, execution_1.executeClientOperation)(() => this.pool.connect());
|
|
26
|
-
const eventManager = new EventManager_1.
|
|
27
|
+
const eventManager = new EventManager_1.EventManager((_a = options.eventManager) !== null && _a !== void 0 ? _a : this.eventManager);
|
|
27
28
|
await (0, execution_1.executeQuery)(client, eventManager, {
|
|
28
29
|
sql: 'BEGIN',
|
|
29
30
|
...this.queryConfig,
|
|
@@ -44,11 +45,11 @@ class Connection {
|
|
|
44
45
|
async end() {
|
|
45
46
|
await (0, execution_1.executeClientOperation)(() => this.pool.end());
|
|
46
47
|
}
|
|
47
|
-
async query(sql, parameters = [], meta = {}, config = {}) {
|
|
48
|
+
async query(sql, parameters = [], meta = {}, { eventManager, ...config } = {}) {
|
|
48
49
|
const client = await (0, execution_1.executeClientOperation)(() => this.pool.connect());
|
|
49
50
|
const query = { sql, parameters, meta, ...this.queryConfig, ...config };
|
|
50
51
|
try {
|
|
51
|
-
const result = await (0, execution_1.executeQuery)(client, this.eventManager, query, {});
|
|
52
|
+
const result = await (0, execution_1.executeQuery)(client, eventManager !== null && eventManager !== void 0 ? eventManager : this.eventManager, query, {});
|
|
52
53
|
client.release();
|
|
53
54
|
return result;
|
|
54
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../../src/client/Connection.ts"],"names":[],"mappings":";;;AAAA,2BAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../../src/client/Connection.ts"],"names":[],"mappings":";;;AAAA,2BAAqC;AACrC,iDAA6C;AAC7C,qCAAiC;AACjC,+CAA2C;AAC3C,2CAAkE;AAElE,MAAM,UAAU;IAGf,YACiB,MAAkB,EACjB,WAAmC,EACpC,eAA6B,IAAI,2BAAY,CAAC,IAAI,CAAC;QAFnD,WAAM,GAAN,MAAM,CAAY;QAC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AG,IAAI,EAAE;SAC/B,CAAA;IACF,CAAC;CACD;AAsEQ,gCAAU;AApEnB,WAAU,UAAU;IA+DN,0BAAe,GAAG,iDAAiD,CAAA;AAGjF,CAAC,EAlES,UAAU,KAAV,UAAU,QAkEnB;AAEQ,gCAAU"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { Connection } from './Connection';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
declare class EventManager {
|
|
3
|
+
readonly parent: EventManager | null;
|
|
4
4
|
private readonly listeners;
|
|
5
5
|
constructor(parent?: EventManager | null);
|
|
6
6
|
on<Event extends keyof EventManager.ListenerTypes>(event: Event, cb: EventManager.ListenerTypes[Event]): void;
|
|
7
7
|
fire<Event extends EventManager.Event>(event: Event, ...params: Parameters<EventManager.ListenerTypes[Event]>): void;
|
|
8
8
|
removeListener<Event extends EventManager.Event>(event: EventManager.Event, cb: EventManager.ListenerTypes[Event]): void;
|
|
9
9
|
}
|
|
10
|
-
declare type EventManager = {
|
|
11
|
-
[P in keyof EventManagerImpl]: EventManagerImpl[P];
|
|
12
|
-
};
|
|
13
10
|
declare namespace EventManager {
|
|
14
11
|
enum Event {
|
|
15
12
|
queryStart = "queryStart",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventManager.d.ts","sourceRoot":"","sources":["../../../src/client/EventManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,
|
|
1
|
+
{"version":3,"file":"EventManager.d.ts","sourceRoot":"","sources":["../../../src/client/EventManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,cAAM,YAAY;aASA,MAAM,EAAE,YAAY,GAAG,IAAI;IAR5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAKzB;gBAGgB,MAAM,GAAE,YAAY,GAAG,IAAW;IAGnD,EAAE,CAAC,KAAK,SAAS,MAAM,YAAY,CAAC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Aa,GAAG;SAAG,CAAC,IAAI,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE;KAAE,CAAA;CAC9E;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventManager =
|
|
4
|
-
class
|
|
3
|
+
exports.EventManager = void 0;
|
|
4
|
+
class EventManager {
|
|
5
5
|
constructor(parent = null) {
|
|
6
6
|
this.parent = parent;
|
|
7
7
|
this.listeners = {
|
|
@@ -24,8 +24,7 @@ class EventManagerImpl {
|
|
|
24
24
|
this.listeners[event] = this.listeners[event].filter(it => it !== cb);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
exports.
|
|
28
|
-
var EventManager;
|
|
27
|
+
exports.EventManager = EventManager;
|
|
29
28
|
(function (EventManager) {
|
|
30
29
|
let Event;
|
|
31
30
|
(function (Event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventManager.js","sourceRoot":"","sources":["../../../src/client/EventManager.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"EventManager.js","sourceRoot":"","sources":["../../../src/client/EventManager.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY;IAQjB,YACiB,SAA8B,IAAI;QAAlC,WAAM,GAAN,MAAM,CAA4B;QARlC,cAAS,GAAG;YAC5B,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,EAAuC;YACxE,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAqC;YACpE,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,EAAuC;YACxE,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAwC;SAC1E,CAAA;IAIE,CAAC;IAEJ,EAAE,CAAiD,KAAY,EAAE,EAAqC;QACpG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAyC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACxE,CAAC;IAED,IAAI,CAAmC,KAAY,EAAE,GAAG,MAAqD;QAC3G,IAAI,CAAC,SAAS,CAAC,KAAK,CAAyC,CAAC,OAAO,CAAC,CAAC,EAAqC,EAAE,EAAE,CAChH,EAAE,CAAC,GAAI,MAAqB,CAAC,CAC7B,CAAA;QACD,IAAI,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAA;SAClC;IACF,CAAC;IAED,cAAc,CACb,KAAyB,EACzB,EAAqC;QAErC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAyC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAU,CAAA;IACxH,CAAC;CACD;AA0BQ,oCAAY;AAvBrB,WAAU,YAAY;IACrB,IAAY,KAKX;IALD,WAAY,KAAK;QAChB,kCAAyB,CAAA;QACzB,8BAAqB,CAAA;QACrB,kCAAyB,CAAA;QACzB,oCAA2B,CAAA;IAC5B,CAAC,EALW,KAAK,GAAL,kBAAK,KAAL,kBAAK,QAKhB;AAeF,CAAC,EArBS,YAAY,KAAZ,YAAY,QAqBrB;AAEQ,oCAAY"}
|
|
@@ -9,7 +9,9 @@ declare class SingleConnection implements Connection.ConnectionLike, Connection.
|
|
|
9
9
|
private isConnected;
|
|
10
10
|
constructor(pgClient: PgClient, queryConfig: Connection.QueryConfig, eventManager?: EventManager, isConnected?: boolean);
|
|
11
11
|
createClient(schema: string, queryMeta: Record<string, any>): Client;
|
|
12
|
-
transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result
|
|
12
|
+
transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result, options?: {
|
|
13
|
+
eventManager?: EventManager;
|
|
14
|
+
}): Promise<Result>;
|
|
13
15
|
end(): Promise<void>;
|
|
14
16
|
query<Row extends Record<string, any>>(sql: string, parameters?: any[], meta?: Record<string, any>, config?: Connection.QueryConfig): Promise<Connection.Result<Row>>;
|
|
15
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleConnection.d.ts","sourceRoot":"","sources":["../../../src/client/SingleConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"SingleConnection.d.ts","sourceRoot":"","sources":["../../../src/client/SingleConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,cAAM,gBAAiB,YAAW,UAAU,CAAC,cAAc,EAAE,UAAU,CAAC,aAAa;IAEnF,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;aACZ,YAAY,EAAE,YAAY;IAC1C,OAAO,CAAC,WAAW;gBAHF,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,UAAU,CAAC,WAAW,EACpC,YAAY,GAAE,YAAqC,EAC3D,WAAW,UAAQ;IAGrB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;IAIrE,WAAW,CAAC,MAAM,EACvB,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,EAC9E,OAAO,GAAE;QAAE,YAAY,CAAC,EAAE,YAAY,CAAA;KAAO,GAC3C,OAAO,CAAC,MAAM,CAAC;IA2BZ,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAKpB,KAAK,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1C,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,GAAG,EAAO,EACtB,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAC9B,MAAM,GAAE,UAAU,CAAC,WAAgB,GACjC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;CAYlC;AACD,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -6,21 +6,22 @@ const Client_1 = require("./Client");
|
|
|
6
6
|
const Transaction_1 = require("./Transaction");
|
|
7
7
|
const execution_1 = require("./execution");
|
|
8
8
|
class SingleConnection {
|
|
9
|
-
constructor(pgClient, queryConfig, eventManager = new EventManager_1.
|
|
9
|
+
constructor(pgClient, queryConfig, eventManager = new EventManager_1.EventManager(null), isConnected = false) {
|
|
10
10
|
this.pgClient = pgClient;
|
|
11
11
|
this.queryConfig = queryConfig;
|
|
12
12
|
this.eventManager = eventManager;
|
|
13
13
|
this.isConnected = isConnected;
|
|
14
14
|
}
|
|
15
15
|
createClient(schema, queryMeta) {
|
|
16
|
-
return new Client_1.Client(this, schema, queryMeta);
|
|
16
|
+
return new Client_1.Client(this, schema, queryMeta, new EventManager_1.EventManager(this.eventManager));
|
|
17
17
|
}
|
|
18
|
-
async transaction(callback) {
|
|
18
|
+
async transaction(callback, options = {}) {
|
|
19
|
+
var _a;
|
|
19
20
|
if (!this.isConnected) {
|
|
20
21
|
await this.pgClient.connect();
|
|
21
22
|
this.isConnected = true;
|
|
22
23
|
}
|
|
23
|
-
const eventManager = new EventManager_1.
|
|
24
|
+
const eventManager = new EventManager_1.EventManager((_a = options.eventManager) !== null && _a !== void 0 ? _a : this.eventManager);
|
|
24
25
|
await (0, execution_1.executeQuery)(this.pgClient, eventManager, {
|
|
25
26
|
sql: 'BEGIN',
|
|
26
27
|
...this.queryConfig,
|
|
@@ -41,13 +42,14 @@ class SingleConnection {
|
|
|
41
42
|
await this.pgClient.end();
|
|
42
43
|
}
|
|
43
44
|
async query(sql, parameters = [], meta = {}, config = {}) {
|
|
45
|
+
var _a;
|
|
44
46
|
if (!this.isConnected) {
|
|
45
47
|
await this.pgClient.connect();
|
|
46
48
|
this.isConnected = true;
|
|
47
49
|
}
|
|
48
50
|
const query = { sql, parameters, meta, ...this.queryConfig, ...config };
|
|
49
51
|
try {
|
|
50
|
-
return await (0, execution_1.executeQuery)(this.pgClient, this.eventManager, query, {});
|
|
52
|
+
return await (0, execution_1.executeQuery)(this.pgClient, (_a = config.eventManager) !== null && _a !== void 0 ? _a : this.eventManager, query, {});
|
|
51
53
|
}
|
|
52
54
|
catch (e) {
|
|
53
55
|
throw e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleConnection.js","sourceRoot":"","sources":["../../../src/client/SingleConnection.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"SingleConnection.js","sourceRoot":"","sources":["../../../src/client/SingleConnection.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AAC7C,qCAAiC;AACjC,+CAA2C;AAC3C,2CAA0C;AAG1C,MAAM,gBAAgB;IACrB,YACkB,QAAkB,EAClB,WAAmC,EACpC,eAA6B,IAAI,2BAAY,CAAC,IAAI,CAAC,EAC3D,cAAc,KAAK;QAHV,aAAQ,GAAR,QAAQ,CAAU;QAClB,gBAAW,GAAX,WAAW,CAAwB;QACpC,iBAAY,GAAZ,YAAY,CAAuC;QAC3D,gBAAW,GAAX,WAAW,CAAQ;IACzB,CAAC;IAEG,YAAY,CAAC,MAAc,EAAE,SAA8B;QACjE,OAAO,IAAI,eAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,2BAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAA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AAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,MAAM,EAAE,CAAA;QACzF,IAAI;YACH,OAAO,MAAM,IAAA,wBAAY,EAAM,IAAI,CAAC,QAAQ,EAAE,MAAA,MAAM,CAAC,YAAY,mCAAI,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;SAClG;QAAC,OAAO,CAAC,EAAE;YACX,MAAM,CAAC,CAAA;SACP;IACF,CAAC;CACD;AACQ,4CAAgB"}
|
|
@@ -10,7 +10,9 @@ export declare class Transaction implements Connection.TransactionLike {
|
|
|
10
10
|
private savepointCounter;
|
|
11
11
|
get isClosed(): boolean;
|
|
12
12
|
constructor(pgClient: ClientBase, eventManager: EventManager, config: Connection.QueryConfig);
|
|
13
|
-
transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result
|
|
13
|
+
transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result, options?: {
|
|
14
|
+
eventManager?: EventManager;
|
|
15
|
+
}): Promise<Result>;
|
|
14
16
|
query<Row extends Record<string, any>>(sql: string, parameters?: any[], meta?: Record<string, any>, config?: Connection.QueryConfig): Promise<Connection.Result<Row>>;
|
|
15
17
|
rollback(): Promise<void>;
|
|
16
18
|
rollbackUnclosed(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../../src/client/Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../../src/client/Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAg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 0;
|
|
4
|
+
const EventManager_1 = require("./EventManager");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
6
|
const execution_1 = require("./execution");
|
|
6
7
|
class Transaction {
|
|
@@ -15,10 +16,11 @@ class Transaction {
|
|
|
15
16
|
get isClosed() {
|
|
16
17
|
return this._isClosed;
|
|
17
18
|
}
|
|
18
|
-
async transaction(callback) {
|
|
19
|
+
async transaction(callback, options) {
|
|
20
|
+
var _a;
|
|
19
21
|
const savepointName = `savepoint_${this.savepointCounter++}`;
|
|
20
22
|
await this.query(`SAVEPOINT ${(0, utils_1.wrapIdentifier)(savepointName)}`);
|
|
21
|
-
const savepoint = new SavePoint(savepointName, this, this.pgClient);
|
|
23
|
+
const savepoint = new SavePoint(savepointName, this, this.pgClient, new EventManager_1.EventManager((_a = options === null || options === void 0 ? void 0 : options.eventManager) !== null && _a !== void 0 ? _a : this.eventManager));
|
|
22
24
|
try {
|
|
23
25
|
const result = await callback(savepoint);
|
|
24
26
|
if (!savepoint.isClosed) {
|
|
@@ -64,20 +66,21 @@ class Transaction {
|
|
|
64
66
|
}
|
|
65
67
|
exports.Transaction = Transaction;
|
|
66
68
|
class SavePoint {
|
|
67
|
-
constructor(savepointName, transactionInst, pgClient) {
|
|
69
|
+
constructor(savepointName, transactionInst, pgClient, eventManager) {
|
|
68
70
|
this.savepointName = savepointName;
|
|
69
71
|
this.transactionInst = transactionInst;
|
|
70
72
|
this.pgClient = pgClient;
|
|
73
|
+
this.eventManager = eventManager;
|
|
71
74
|
this._isClosed = false;
|
|
72
75
|
}
|
|
73
76
|
get isClosed() {
|
|
74
77
|
return this._isClosed;
|
|
75
78
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
async transaction(callback, options) {
|
|
80
|
+
var _a;
|
|
81
|
+
return await this.transactionInst.transaction(callback, {
|
|
82
|
+
eventManager: (_a = options === null || options === void 0 ? void 0 : options.eventManager) !== null && _a !== void 0 ? _a : this.eventManager,
|
|
83
|
+
});
|
|
81
84
|
}
|
|
82
85
|
async query(sql, parameters = [], meta = {}) {
|
|
83
86
|
if (this.isClosed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/client/Transaction.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/client/Transaction.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AAE7C,oCAAyC;AACzC,2CAA0C;AAE1C,MAAa,WAAW;IAWvB,YACkB,QAAoB,EACrB,YAA0B,EACzB,MAA8B;QAF9B,aAAQ,GAAR,QAAQ,CAAY;QACrB,iBAAY,GAAZ,YAAY,CAAc;QACzB,WAAM,GAAN,MAAM,CAAwB;QAbxC,cAAS,GAAG,KAAK,CAAA;QAEjB,iBAAY,GAA4B,EAAE,CAAA;QAE1C,qBAAgB,GAAG,CAAC,CAAA;IAUzB,CAAC;IARJ,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,SAAS,CAAA;IACtB,CAAC;IAQD,KAAK,CAAC,WAAW,CAChB,QAA8E,EAC9E,OAAyC;;QAEzC,MAAM,aAAa,GAAG,aAAa,IAAI,CAAC,gBAAgB,EAAE,EAAE,CAAA;QAC5D,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,IAAA,sBAAc,EAAC,aAAa,CAAC,EAAE,CAAC,CAAA;QAC9D,MAAM,SAAS,GAAG,IAAI,SAAS,CAC9B,aAAa,EACb,IAAI,EACJ,IAAI,CAAC,QAAQ,EACb,IAAI,2BAAY,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,IAAI,CAAC,YAAY,CAAC,CAC5D,CAAA;QACD,IAAI;YACH,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAA;YACxC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;gBACxB,MAAM,SAAS,CA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