@mikro-orm/knex 6.0.0-dev.48 → 6.0.0-dev.49
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.
|
@@ -7,6 +7,9 @@ export declare abstract class AbstractSqlConnection extends Connection {
|
|
|
7
7
|
protected platform: AbstractSqlPlatform;
|
|
8
8
|
protected client: Knex;
|
|
9
9
|
constructor(config: Configuration, options?: ConnectionOptions, type?: 'read' | 'write');
|
|
10
|
+
abstract createKnex(): void;
|
|
11
|
+
/** @inheritDoc */
|
|
12
|
+
connect(): void | Promise<void>;
|
|
10
13
|
getKnex(): Knex;
|
|
11
14
|
close(force?: boolean): Promise<void>;
|
|
12
15
|
isConnected(): Promise<boolean>;
|
package/AbstractSqlConnection.js
CHANGED
|
@@ -14,16 +14,23 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
14
14
|
super(config, options, type);
|
|
15
15
|
this.patchKnexClient();
|
|
16
16
|
}
|
|
17
|
+
/** @inheritDoc */
|
|
18
|
+
connect() {
|
|
19
|
+
this.createKnex();
|
|
20
|
+
}
|
|
17
21
|
getKnex() {
|
|
22
|
+
if (!this.client) {
|
|
23
|
+
this.createKnex();
|
|
24
|
+
}
|
|
18
25
|
return this.client;
|
|
19
26
|
}
|
|
20
27
|
async close(force) {
|
|
21
28
|
await super.close(force);
|
|
22
|
-
await this.
|
|
29
|
+
await this.getKnex().destroy();
|
|
23
30
|
}
|
|
24
31
|
async isConnected() {
|
|
25
32
|
try {
|
|
26
|
-
await this.
|
|
33
|
+
await this.getKnex().raw('select 1');
|
|
27
34
|
return true;
|
|
28
35
|
}
|
|
29
36
|
catch {
|
|
@@ -46,7 +53,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
46
53
|
if (!options.ctx) {
|
|
47
54
|
await options.eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionStart);
|
|
48
55
|
}
|
|
49
|
-
const trx = await (options.ctx || this.
|
|
56
|
+
const trx = await (options.ctx || this.getKnex()).transaction(null, { isolationLevel: options.isolationLevel });
|
|
50
57
|
if (!options.ctx) {
|
|
51
58
|
await options.eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionStart, trx);
|
|
52
59
|
}
|
|
@@ -87,7 +94,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
87
94
|
const formatted = this.platform.formatQuery(queryOrKnex, params);
|
|
88
95
|
const sql = this.getSql(queryOrKnex, formatted);
|
|
89
96
|
const res = await this.executeQuery(sql, () => {
|
|
90
|
-
const query = this.
|
|
97
|
+
const query = this.getKnex().raw(formatted);
|
|
91
98
|
if (ctx) {
|
|
92
99
|
query.transacting(ctx);
|
|
93
100
|
}
|
|
@@ -100,7 +107,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
100
107
|
*/
|
|
101
108
|
async loadFile(path) {
|
|
102
109
|
const buf = await (0, fs_extra_1.readFile)(path);
|
|
103
|
-
await this.
|
|
110
|
+
await this.getKnex().raw(buf.toString());
|
|
104
111
|
}
|
|
105
112
|
createKnexClient(type) {
|
|
106
113
|
const driverOptions = this.config.get('driverOptions');
|
|
@@ -147,7 +154,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
147
154
|
if (logger.isEnabled('query-params')) {
|
|
148
155
|
return formatted;
|
|
149
156
|
}
|
|
150
|
-
return this.
|
|
157
|
+
return this.getKnex().client.positionBindings(query);
|
|
151
158
|
}
|
|
152
159
|
/**
|
|
153
160
|
* do not call `positionBindings` when there are no bindings - it was messing up with
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.49",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^5.6.15"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
69
|
+
"@mikro-orm/core": "~6.0.0-dev.49"
|
|
70
70
|
}
|
|
71
71
|
}
|