@mikro-orm/knex 6.4.6-dev.9 → 7.0.0-dev.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/AbstractSqlConnection.d.ts +15 -25
- package/AbstractSqlConnection.js +98 -126
- package/AbstractSqlDriver.d.ts +20 -13
- package/AbstractSqlDriver.js +73 -54
- package/AbstractSqlPlatform.d.ts +15 -3
- package/AbstractSqlPlatform.js +32 -11
- package/README.md +0 -2
- package/SqlEntityManager.d.ts +5 -6
- package/SqlEntityManager.js +5 -5
- package/SqlEntityRepository.d.ts +1 -6
- package/SqlEntityRepository.js +0 -6
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +161 -0
- package/dialects/mssql/index.d.ts +1 -1
- package/dialects/mssql/index.js +1 -1
- package/dialects/mysql/MySqlExceptionConverter.js +1 -0
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +7 -0
- package/dialects/mysql/MySqlNativeQueryBuilder.js +81 -0
- package/dialects/mysql/MySqlPlatform.d.ts +5 -1
- package/dialects/mysql/MySqlPlatform.js +9 -1
- package/dialects/mysql/MySqlSchemaHelper.d.ts +6 -12
- package/dialects/mysql/MySqlSchemaHelper.js +42 -75
- package/dialects/mysql/index.d.ts +1 -3
- package/dialects/mysql/index.js +1 -3
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +5 -0
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +12 -0
- package/dialects/postgresql/index.d.ts +1 -1
- package/dialects/postgresql/index.js +1 -1
- package/dialects/sqlite/BaseSqliteConnection.d.ts +0 -5
- package/dialects/sqlite/BaseSqliteConnection.js +4 -42
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +15 -3
- package/dialects/sqlite/BaseSqlitePlatform.js +20 -4
- package/dialects/sqlite/SqliteExceptionConverter.d.ts +9 -0
- package/dialects/sqlite/SqliteExceptionConverter.js +55 -0
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +6 -0
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +15 -0
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +38 -0
- package/dialects/sqlite/SqliteSchemaHelper.js +384 -0
- package/dialects/sqlite/index.d.ts +3 -5
- package/dialects/sqlite/index.js +3 -5
- package/index.d.ts +1 -2
- package/index.js +3 -5
- package/index.mjs +10 -13
- package/package.json +4 -18
- package/query/CriteriaNodeFactory.js +5 -5
- package/query/NativeQueryBuilder.d.ts +108 -0
- package/query/NativeQueryBuilder.js +429 -0
- package/query/ObjectCriteriaNode.js +3 -3
- package/query/QueryBuilder.d.ts +30 -34
- package/query/QueryBuilder.js +112 -123
- package/query/QueryBuilderHelper.d.ts +27 -23
- package/query/QueryBuilderHelper.js +174 -168
- package/query/ScalarCriteriaNode.js +4 -0
- package/query/index.d.ts +1 -0
- package/query/index.js +1 -0
- package/schema/DatabaseSchema.js +9 -6
- package/schema/DatabaseTable.d.ts +2 -1
- package/schema/DatabaseTable.js +9 -5
- package/schema/SchemaComparator.d.ts +1 -2
- package/schema/SchemaComparator.js +31 -18
- package/schema/SchemaHelper.d.ts +27 -33
- package/schema/SchemaHelper.js +294 -184
- package/schema/SqlSchemaGenerator.d.ts +3 -9
- package/schema/SqlSchemaGenerator.js +105 -229
- package/typings.d.ts +7 -17
- package/MonkeyPatchable.d.ts +0 -18
- package/MonkeyPatchable.js +0 -60
- package/dialects/mssql/MsSqlColumnCompiler.d.ts +0 -4
- package/dialects/mssql/MsSqlColumnCompiler.js +0 -10
- package/dialects/mssql/MsSqlKnexDialect.d.ts +0 -6
- package/dialects/mssql/MsSqlKnexDialect.js +0 -22
- package/dialects/mssql/MsSqlQueryCompiler.d.ts +0 -12
- package/dialects/mssql/MsSqlQueryCompiler.js +0 -94
- package/dialects/mssql/MsSqlTableCompiler.d.ts +0 -9
- package/dialects/mssql/MsSqlTableCompiler.js +0 -40
- package/dialects/mysql/MariaDbKnexDialect.d.ts +0 -6
- package/dialects/mysql/MariaDbKnexDialect.js +0 -16
- package/dialects/mysql/MySqlColumnCompiler.d.ts +0 -7
- package/dialects/mysql/MySqlColumnCompiler.js +0 -26
- package/dialects/mysql/MySqlConnection.d.ts +0 -8
- package/dialects/mysql/MySqlConnection.js +0 -43
- package/dialects/mysql/MySqlKnexDialect.d.ts +0 -5
- package/dialects/mysql/MySqlKnexDialect.js +0 -17
- package/dialects/mysql/MySqlQueryCompiler.d.ts +0 -5
- package/dialects/mysql/MySqlQueryCompiler.js +0 -23
- package/dialects/postgresql/PostgreSqlKnexDialect.d.ts +0 -7
- package/dialects/postgresql/PostgreSqlKnexDialect.js +0 -20
- package/dialects/postgresql/PostgreSqlQueryCompiler.d.ts +0 -4
- package/dialects/postgresql/PostgreSqlQueryCompiler.js +0 -13
- package/dialects/postgresql/PostgreSqlTableCompiler.d.ts +0 -11
- package/dialects/postgresql/PostgreSqlTableCompiler.js +0 -89
- package/dialects/sqlite/BaseSqliteSchemaHelper.d.ts +0 -28
- package/dialects/sqlite/BaseSqliteSchemaHelper.js +0 -200
- package/dialects/sqlite/BetterSqliteKnexDialect.d.ts +0 -5
- package/dialects/sqlite/BetterSqliteKnexDialect.js +0 -15
- package/dialects/sqlite/LibSqlKnexDialect.d.ts +0 -11
- package/dialects/sqlite/LibSqlKnexDialect.js +0 -85
- package/dialects/sqlite/SqliteKnexDialect.d.ts +0 -8
- package/dialects/sqlite/SqliteKnexDialect.js +0 -67
- package/dialects/sqlite/SqliteTableCompiler.d.ts +0 -6
- package/dialects/sqlite/SqliteTableCompiler.js +0 -71
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type ControlledTransaction, type Dialect, Kysely } from 'kysely';
|
|
2
|
+
import { type AnyEntity, Connection, type Dictionary, type EntityData, type IsolationLevel, type LoggingOptions, type QueryResult, RawQueryFragment, type Transaction, type TransactionEventBroadcaster } from '@mikro-orm/core';
|
|
3
3
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
4
|
+
import { NativeQueryBuilder } from './query';
|
|
4
5
|
export declare abstract class AbstractSqlConnection extends Connection {
|
|
5
|
-
private static __patched;
|
|
6
6
|
protected platform: AbstractSqlPlatform;
|
|
7
|
-
protected client:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/** @inheritDoc */
|
|
11
|
-
connect(): void | Promise<void>;
|
|
12
|
-
getKnex(): Knex;
|
|
7
|
+
protected client: Kysely<any>;
|
|
8
|
+
abstract createKyselyDialect(overrides: Dictionary): Dialect;
|
|
9
|
+
connect(): Promise<void>;
|
|
13
10
|
/**
|
|
14
11
|
* @inheritDoc
|
|
15
12
|
*/
|
|
@@ -28,33 +25,26 @@ export declare abstract class AbstractSqlConnection extends Connection {
|
|
|
28
25
|
reason: string;
|
|
29
26
|
error?: Error;
|
|
30
27
|
}>;
|
|
31
|
-
|
|
28
|
+
getClient<T = any>(): Kysely<T>;
|
|
29
|
+
transactional<T>(cb: (trx: Transaction<ControlledTransaction<any, any>>) => Promise<T>, options?: {
|
|
32
30
|
isolationLevel?: IsolationLevel;
|
|
33
31
|
readOnly?: boolean;
|
|
34
|
-
ctx?:
|
|
32
|
+
ctx?: ControlledTransaction<any>;
|
|
35
33
|
eventBroadcaster?: TransactionEventBroadcaster;
|
|
36
34
|
}): Promise<T>;
|
|
37
35
|
begin(options?: {
|
|
38
36
|
isolationLevel?: IsolationLevel;
|
|
39
37
|
readOnly?: boolean;
|
|
40
|
-
ctx?:
|
|
38
|
+
ctx?: ControlledTransaction<any, any>;
|
|
41
39
|
eventBroadcaster?: TransactionEventBroadcaster;
|
|
42
|
-
}): Promise<
|
|
43
|
-
commit(ctx:
|
|
44
|
-
rollback(ctx:
|
|
45
|
-
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(
|
|
40
|
+
}): Promise<ControlledTransaction<any, any>>;
|
|
41
|
+
commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
42
|
+
rollback(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
43
|
+
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: readonly unknown[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions): Promise<T>;
|
|
46
44
|
/**
|
|
47
45
|
* Execute raw SQL queries from file
|
|
48
46
|
*/
|
|
49
47
|
loadFile(path: string): Promise<void>;
|
|
50
|
-
protected createKnexClient(type: string): Knex;
|
|
51
|
-
protected getKnexOptions(type: string): Knex.Config;
|
|
52
48
|
private getSql;
|
|
53
|
-
|
|
54
|
-
* do not call `positionBindings` when there are no bindings - it was messing up with
|
|
55
|
-
* already interpolated strings containing `?`, and escaping that was not enough to
|
|
56
|
-
* support edge cases like `\\?` strings (as `positionBindings` was removing the `\\`)
|
|
57
|
-
*/
|
|
58
|
-
private patchKnexClient;
|
|
59
|
-
protected abstract transformRawResult<T>(res: any, method: 'all' | 'get' | 'run'): T;
|
|
49
|
+
protected transformRawResult<T>(res: any, method?: 'all' | 'get' | 'run'): T;
|
|
60
50
|
}
|
package/AbstractSqlConnection.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractSqlConnection = void 0;
|
|
4
|
-
const
|
|
4
|
+
const kysely_1 = require("kysely");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const core_1 = require("@mikro-orm/core");
|
|
7
|
-
const
|
|
8
|
-
const parentTransactionSymbol = Symbol('parentTransaction');
|
|
9
|
-
function isRootTransaction(trx) {
|
|
10
|
-
return !Object.getOwnPropertySymbols(trx).includes(parentTransactionSymbol);
|
|
11
|
-
}
|
|
7
|
+
const query_1 = require("./query");
|
|
12
8
|
class AbstractSqlConnection extends core_1.Connection {
|
|
13
|
-
static __patched = false;
|
|
14
9
|
client;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** @inheritDoc */
|
|
20
|
-
connect() {
|
|
21
|
-
this.createKnex();
|
|
22
|
-
}
|
|
23
|
-
getKnex() {
|
|
24
|
-
if (!this.client) {
|
|
25
|
-
this.createKnex();
|
|
10
|
+
async connect() {
|
|
11
|
+
let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');
|
|
12
|
+
if (typeof driverOptions === 'function') {
|
|
13
|
+
driverOptions = await driverOptions();
|
|
26
14
|
}
|
|
27
|
-
|
|
15
|
+
if (driverOptions instanceof kysely_1.Kysely) {
|
|
16
|
+
this.logger.log('info', 'Reusing Kysely client provided via `driverOptions`');
|
|
17
|
+
this.client = driverOptions;
|
|
18
|
+
}
|
|
19
|
+
else if ('createDriver' in driverOptions) {
|
|
20
|
+
this.logger.log('info', 'Reusing Kysely dialect provided via `driverOptions`');
|
|
21
|
+
this.client = new kysely_1.Kysely({ dialect: driverOptions });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.client = new kysely_1.Kysely({
|
|
25
|
+
dialect: this.createKyselyDialect(driverOptions),
|
|
26
|
+
// log: m => console.log(m),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
this.connected = true;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* @inheritDoc
|
|
31
33
|
*/
|
|
32
34
|
async close(force) {
|
|
33
35
|
await super.close(force);
|
|
34
|
-
await this.
|
|
36
|
+
await this.client?.destroy();
|
|
37
|
+
this.connected = false;
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* @inheritDoc
|
|
@@ -44,14 +47,20 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
44
47
|
* @inheritDoc
|
|
45
48
|
*/
|
|
46
49
|
async checkConnection() {
|
|
50
|
+
if (!this.connected) {
|
|
51
|
+
return { ok: false, reason: 'Connection not established' };
|
|
52
|
+
}
|
|
47
53
|
try {
|
|
48
|
-
await this.
|
|
54
|
+
await this.client.executeQuery(kysely_1.CompiledQuery.raw('select 1'));
|
|
49
55
|
return { ok: true };
|
|
50
56
|
}
|
|
51
57
|
catch (error) {
|
|
52
58
|
return { ok: false, reason: error.message, error };
|
|
53
59
|
}
|
|
54
60
|
}
|
|
61
|
+
getClient() {
|
|
62
|
+
return this.client;
|
|
63
|
+
}
|
|
55
64
|
async transactional(cb, options = {}) {
|
|
56
65
|
const trx = await this.begin(options);
|
|
57
66
|
try {
|
|
@@ -65,61 +74,74 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
async begin(options = {}) {
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
if (options.ctx) {
|
|
78
|
+
const ctx = options.ctx;
|
|
79
|
+
ctx.index ??= 0;
|
|
80
|
+
const savepointName = `trx${ctx.index + 1}`;
|
|
81
|
+
const trx = await options.ctx.savepoint(savepointName).execute();
|
|
82
|
+
Reflect.defineProperty(trx, 'index', { value: ctx.index + 1 });
|
|
83
|
+
Reflect.defineProperty(trx, 'savepointName', { value: savepointName });
|
|
84
|
+
this.logQuery(this.platform.getSavepointSQL(savepointName));
|
|
85
|
+
return trx;
|
|
86
|
+
}
|
|
87
|
+
await options.eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionStart);
|
|
88
|
+
let trxBuilder = this.client.startTransaction();
|
|
89
|
+
if (options.isolationLevel) {
|
|
90
|
+
trxBuilder = trxBuilder.setIsolationLevel(options.isolationLevel);
|
|
91
|
+
}
|
|
92
|
+
const trx = await trxBuilder.execute();
|
|
93
|
+
for (const query of this.platform.getBeginTransactionSQL(options)) {
|
|
94
|
+
this.logQuery(query);
|
|
95
|
+
}
|
|
96
|
+
await options.eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionStart, trx);
|
|
81
97
|
return trx;
|
|
82
98
|
}
|
|
83
99
|
async commit(ctx, eventBroadcaster) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionCommit, ctx);
|
|
100
|
+
if (ctx.isRolledBack) {
|
|
101
|
+
return;
|
|
87
102
|
}
|
|
88
|
-
ctx
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
103
|
+
if ('savepointName' in ctx) {
|
|
104
|
+
await ctx.releaseSavepoint(ctx.savepointName).execute();
|
|
105
|
+
this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
|
|
106
|
+
return;
|
|
92
107
|
}
|
|
108
|
+
await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionCommit, ctx);
|
|
109
|
+
await ctx.commit().execute();
|
|
110
|
+
this.logQuery(this.platform.getCommitTransactionSQL());
|
|
111
|
+
await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionCommit, ctx);
|
|
93
112
|
}
|
|
94
113
|
async rollback(ctx, eventBroadcaster) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
await ctx.rollback();
|
|
100
|
-
if (runTrxHooks) {
|
|
101
|
-
await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionRollback, ctx);
|
|
114
|
+
if ('savepointName' in ctx) {
|
|
115
|
+
await ctx.rollbackToSavepoint(ctx.savepointName).execute();
|
|
116
|
+
this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName));
|
|
117
|
+
return;
|
|
102
118
|
}
|
|
119
|
+
await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionRollback, ctx);
|
|
120
|
+
await ctx.rollback().execute();
|
|
121
|
+
this.logQuery(this.platform.getRollbackTransactionSQL());
|
|
122
|
+
await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionRollback, ctx);
|
|
103
123
|
}
|
|
104
|
-
async execute(
|
|
124
|
+
async execute(query, params = [], method = 'all', ctx, loggerContext) {
|
|
105
125
|
await this.ensureConnection();
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
params =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
126
|
+
if (query instanceof query_1.NativeQueryBuilder) {
|
|
127
|
+
query = query.toRaw();
|
|
128
|
+
}
|
|
129
|
+
if (query instanceof core_1.RawQueryFragment) {
|
|
130
|
+
params = query.params;
|
|
131
|
+
query = query.sql;
|
|
132
|
+
}
|
|
133
|
+
query = this.config.get('onQuery')(query, params);
|
|
134
|
+
const formatted = this.platform.formatQuery(query, params);
|
|
135
|
+
const sql = this.getSql(query, formatted, loggerContext);
|
|
115
136
|
return this.executeQuery(sql, async () => {
|
|
116
|
-
const
|
|
137
|
+
const compiled = kysely_1.CompiledQuery.raw(formatted);
|
|
117
138
|
if (ctx) {
|
|
118
|
-
|
|
139
|
+
const res = await ctx.executeQuery(compiled);
|
|
140
|
+
return this.transformRawResult(res, method);
|
|
119
141
|
}
|
|
120
|
-
const res = await
|
|
142
|
+
const res = await this.client.executeQuery(compiled);
|
|
121
143
|
return this.transformRawResult(res, method);
|
|
122
|
-
}, { query
|
|
144
|
+
}, { query, params, ...loggerContext });
|
|
123
145
|
}
|
|
124
146
|
/**
|
|
125
147
|
* Execute raw SQL queries from file
|
|
@@ -127,50 +149,14 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
127
149
|
async loadFile(path) {
|
|
128
150
|
const buf = await (0, fs_extra_1.readFile)(path);
|
|
129
151
|
try {
|
|
130
|
-
|
|
152
|
+
const raw = kysely_1.CompiledQuery.raw(buf.toString());
|
|
153
|
+
await this.client.executeQuery(raw);
|
|
131
154
|
}
|
|
132
155
|
catch (e) {
|
|
133
156
|
/* istanbul ignore next */
|
|
134
157
|
throw this.platform.getExceptionConverter().convertException(e);
|
|
135
158
|
}
|
|
136
159
|
}
|
|
137
|
-
createKnexClient(type) {
|
|
138
|
-
const driverOptions = this.config.get('driverOptions');
|
|
139
|
-
if (driverOptions.context?.client instanceof knex_1.knex.Client) {
|
|
140
|
-
this.logger.log('info', 'Reusing knex client provided via `driverOptions`');
|
|
141
|
-
return driverOptions;
|
|
142
|
-
}
|
|
143
|
-
return (0, knex_1.knex)(this.getKnexOptions(type))
|
|
144
|
-
.on('query', data => {
|
|
145
|
-
if (!data.__knexQueryUid) {
|
|
146
|
-
this.logQuery(data.sql.toLowerCase().replace(/;$/, ''));
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
getKnexOptions(type) {
|
|
151
|
-
const config = core_1.Utils.mergeConfig({
|
|
152
|
-
client: type,
|
|
153
|
-
connection: this.getConnectionOptions(),
|
|
154
|
-
pool: this.config.get('pool'),
|
|
155
|
-
}, this.config.get('driverOptions'), this.options.driverOptions);
|
|
156
|
-
const options = config.connection;
|
|
157
|
-
const password = options.password;
|
|
158
|
-
if (!(password instanceof Function)) {
|
|
159
|
-
return config;
|
|
160
|
-
}
|
|
161
|
-
config.connection = async () => {
|
|
162
|
-
const pw = await password();
|
|
163
|
-
if (typeof pw === 'string') {
|
|
164
|
-
return { ...options, password: pw };
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
...options,
|
|
168
|
-
password: pw.password,
|
|
169
|
-
expirationChecker: pw.expirationChecker,
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
return config;
|
|
173
|
-
}
|
|
174
160
|
getSql(query, formatted, context) {
|
|
175
161
|
const logger = this.config.getLogger();
|
|
176
162
|
if (!logger.isEnabled('query', context)) {
|
|
@@ -179,34 +165,20 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
179
165
|
if (logger.isEnabled('query-params', context)) {
|
|
180
166
|
return formatted;
|
|
181
167
|
}
|
|
182
|
-
return
|
|
168
|
+
return query;
|
|
183
169
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* support edge cases like `\\?` strings (as `positionBindings` was removing the `\\`)
|
|
188
|
-
*/
|
|
189
|
-
patchKnexClient() {
|
|
190
|
-
const { Client, TableCompiler } = MonkeyPatchable_1.MonkeyPatchable;
|
|
191
|
-
const query = Client.prototype.query;
|
|
192
|
-
if (AbstractSqlConnection.__patched) {
|
|
193
|
-
return;
|
|
170
|
+
transformRawResult(res, method) {
|
|
171
|
+
if (method === 'get') {
|
|
172
|
+
return res.rows[0];
|
|
194
173
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
204
|
-
const { __knexUid, __knexTxId } = connection;
|
|
205
|
-
this.emit('query', Object.assign({ __knexUid, __knexTxId }, obj));
|
|
206
|
-
return MonkeyPatchable_1.MonkeyPatchable.QueryExecutioner.executeQuery(connection, obj, this);
|
|
207
|
-
};
|
|
208
|
-
TableCompiler.prototype.raw = function (query) {
|
|
209
|
-
this.pushQuery(query);
|
|
174
|
+
if (method === 'all') {
|
|
175
|
+
return res.rows;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
affectedRows: Number(res.numAffectedRows ?? res.rows.length),
|
|
179
|
+
insertId: res.insertId != null ? Number(res.insertId) : res.insertId,
|
|
180
|
+
row: res.rows[0],
|
|
181
|
+
rows: res.rows,
|
|
210
182
|
};
|
|
211
183
|
}
|
|
212
184
|
}
|
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
|
|
1
|
+
import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, RawQueryFragment, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
|
|
3
2
|
import type { AbstractSqlConnection } from './AbstractSqlConnection';
|
|
4
3
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
5
|
-
import { QueryBuilder, QueryType } from './query';
|
|
4
|
+
import { type NativeQueryBuilder, QueryBuilder, QueryType } from './query';
|
|
6
5
|
import { SqlEntityManager } from './SqlEntityManager';
|
|
7
6
|
import type { Field } from './typings';
|
|
8
7
|
export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlConnection = AbstractSqlConnection, Platform extends AbstractSqlPlatform = AbstractSqlPlatform> extends DatabaseDriver<Connection> {
|
|
@@ -37,7 +36,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
37
36
|
syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
|
|
38
37
|
loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
|
|
39
38
|
private getPivotOrderBy;
|
|
40
|
-
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(
|
|
39
|
+
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions): Promise<T>;
|
|
41
40
|
/**
|
|
42
41
|
* 1:1 owner side needs to be marked for population so QB auto-joins the owner id
|
|
43
42
|
*/
|
|
@@ -45,26 +44,22 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
45
44
|
/**
|
|
46
45
|
* @internal
|
|
47
46
|
*/
|
|
48
|
-
joinedProps<T>(meta: EntityMetadata, populate: PopulateOptions<T>[], options?: {
|
|
47
|
+
joinedProps<T>(meta: EntityMetadata, populate: readonly PopulateOptions<T>[], options?: {
|
|
49
48
|
strategy?: Options['loadStrategy'];
|
|
50
49
|
}): PopulateOptions<T>[];
|
|
51
50
|
/**
|
|
52
51
|
* @internal
|
|
53
52
|
*/
|
|
54
53
|
mergeJoinedResult<T extends object>(rawResults: EntityData<T>[], meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[]): EntityData<T>[];
|
|
55
|
-
protected getFieldsForJoinedLoad<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>,
|
|
56
|
-
strategy?: Options['loadStrategy'];
|
|
57
|
-
populateWhere?: FindOptions<any>['populateWhere'];
|
|
58
|
-
populateFilter?: FindOptions<any>['populateFilter'];
|
|
59
|
-
}, parentTableAlias?: string, parentJoinPath?: string, count?: boolean): Field<T>[];
|
|
54
|
+
protected getFieldsForJoinedLoad<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>, options: FieldsForJoinedLoadOptions<T>): Field<T>[];
|
|
60
55
|
/**
|
|
61
56
|
* @internal
|
|
62
57
|
*/
|
|
63
|
-
mapPropToFieldNames<T extends object>(qb: QueryBuilder<T, any, any, any>, prop: EntityProperty<T>, tableAlias
|
|
58
|
+
mapPropToFieldNames<T extends object>(qb: QueryBuilder<T, any, any, any>, prop: EntityProperty<T>, tableAlias: string): Field<T>[];
|
|
64
59
|
/** @internal */
|
|
65
|
-
createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T, any, any, any>, ctx?: Transaction
|
|
60
|
+
createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T, any, any, any>, ctx?: Transaction, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): QueryBuilder<T, any, any, any>;
|
|
66
61
|
protected resolveConnectionType(args: {
|
|
67
|
-
ctx?: Transaction
|
|
62
|
+
ctx?: Transaction;
|
|
68
63
|
connectionType?: ConnectionType;
|
|
69
64
|
}): ConnectionType;
|
|
70
65
|
protected extractManyToMany<T>(entityName: string, data: EntityDictionary<T>): EntityData<T>;
|
|
@@ -79,3 +74,15 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
79
74
|
protected isPopulated<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>, hint: PopulateOptions<T>, name?: string): boolean;
|
|
80
75
|
protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T, any, any, any>, alias: string, options: Pick<FindOptions<T, any, any, any>, 'strategy' | 'fields' | 'exclude'>, count?: boolean): Field<T>[];
|
|
81
76
|
}
|
|
77
|
+
interface FieldsForJoinedLoadOptions<T extends object> {
|
|
78
|
+
explicitFields?: readonly Field<T>[];
|
|
79
|
+
exclude?: readonly Field<T>[];
|
|
80
|
+
populate?: readonly PopulateOptions<T>[];
|
|
81
|
+
strategy?: Options['loadStrategy'];
|
|
82
|
+
populateWhere?: FindOptions<any>['populateWhere'];
|
|
83
|
+
populateFilter?: FindOptions<any>['populateFilter'];
|
|
84
|
+
parentTableAlias: string;
|
|
85
|
+
parentJoinPath?: string;
|
|
86
|
+
count?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export {};
|