@mikro-orm/knex 6.4.6-dev.9 → 7.0.0-dev.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.
Files changed (101) hide show
  1. package/AbstractSqlConnection.d.ts +15 -25
  2. package/AbstractSqlConnection.js +101 -126
  3. package/AbstractSqlDriver.d.ts +20 -13
  4. package/AbstractSqlDriver.js +73 -54
  5. package/AbstractSqlPlatform.d.ts +15 -3
  6. package/AbstractSqlPlatform.js +32 -11
  7. package/README.md +0 -2
  8. package/SqlEntityManager.d.ts +5 -6
  9. package/SqlEntityManager.js +5 -5
  10. package/SqlEntityRepository.d.ts +1 -6
  11. package/SqlEntityRepository.js +0 -6
  12. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -0
  13. package/dialects/mssql/MsSqlNativeQueryBuilder.js +161 -0
  14. package/dialects/mssql/index.d.ts +1 -1
  15. package/dialects/mssql/index.js +1 -1
  16. package/dialects/mysql/MySqlExceptionConverter.js +1 -0
  17. package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +7 -0
  18. package/dialects/mysql/MySqlNativeQueryBuilder.js +81 -0
  19. package/dialects/mysql/MySqlPlatform.d.ts +10 -2
  20. package/dialects/mysql/MySqlPlatform.js +23 -1
  21. package/dialects/mysql/MySqlSchemaHelper.d.ts +6 -12
  22. package/dialects/mysql/MySqlSchemaHelper.js +42 -75
  23. package/dialects/mysql/index.d.ts +1 -3
  24. package/dialects/mysql/index.js +1 -3
  25. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +5 -0
  26. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +12 -0
  27. package/dialects/postgresql/index.d.ts +1 -1
  28. package/dialects/postgresql/index.js +1 -1
  29. package/dialects/sqlite/BaseSqliteConnection.d.ts +0 -5
  30. package/dialects/sqlite/BaseSqliteConnection.js +4 -42
  31. package/dialects/sqlite/BaseSqlitePlatform.d.ts +15 -3
  32. package/dialects/sqlite/BaseSqlitePlatform.js +20 -4
  33. package/dialects/sqlite/SqliteExceptionConverter.d.ts +9 -0
  34. package/dialects/sqlite/SqliteExceptionConverter.js +55 -0
  35. package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +6 -0
  36. package/dialects/sqlite/SqliteNativeQueryBuilder.js +15 -0
  37. package/dialects/sqlite/SqliteSchemaHelper.d.ts +38 -0
  38. package/dialects/sqlite/SqliteSchemaHelper.js +384 -0
  39. package/dialects/sqlite/index.d.ts +3 -5
  40. package/dialects/sqlite/index.js +3 -5
  41. package/index.d.ts +1 -2
  42. package/index.js +3 -5
  43. package/index.mjs +10 -13
  44. package/package.json +4 -18
  45. package/query/CriteriaNodeFactory.js +5 -5
  46. package/query/NativeQueryBuilder.d.ts +108 -0
  47. package/query/NativeQueryBuilder.js +429 -0
  48. package/query/ObjectCriteriaNode.js +3 -3
  49. package/query/QueryBuilder.d.ts +30 -34
  50. package/query/QueryBuilder.js +112 -123
  51. package/query/QueryBuilderHelper.d.ts +27 -23
  52. package/query/QueryBuilderHelper.js +174 -168
  53. package/query/ScalarCriteriaNode.js +4 -0
  54. package/query/index.d.ts +1 -0
  55. package/query/index.js +1 -0
  56. package/schema/DatabaseSchema.js +9 -6
  57. package/schema/DatabaseTable.d.ts +2 -1
  58. package/schema/DatabaseTable.js +9 -5
  59. package/schema/SchemaComparator.d.ts +1 -2
  60. package/schema/SchemaComparator.js +31 -18
  61. package/schema/SchemaHelper.d.ts +27 -33
  62. package/schema/SchemaHelper.js +294 -184
  63. package/schema/SqlSchemaGenerator.d.ts +3 -9
  64. package/schema/SqlSchemaGenerator.js +105 -229
  65. package/typings.d.ts +7 -17
  66. package/MonkeyPatchable.d.ts +0 -18
  67. package/MonkeyPatchable.js +0 -60
  68. package/dialects/mssql/MsSqlColumnCompiler.d.ts +0 -4
  69. package/dialects/mssql/MsSqlColumnCompiler.js +0 -10
  70. package/dialects/mssql/MsSqlKnexDialect.d.ts +0 -6
  71. package/dialects/mssql/MsSqlKnexDialect.js +0 -22
  72. package/dialects/mssql/MsSqlQueryCompiler.d.ts +0 -12
  73. package/dialects/mssql/MsSqlQueryCompiler.js +0 -94
  74. package/dialects/mssql/MsSqlTableCompiler.d.ts +0 -9
  75. package/dialects/mssql/MsSqlTableCompiler.js +0 -40
  76. package/dialects/mysql/MariaDbKnexDialect.d.ts +0 -6
  77. package/dialects/mysql/MariaDbKnexDialect.js +0 -16
  78. package/dialects/mysql/MySqlColumnCompiler.d.ts +0 -7
  79. package/dialects/mysql/MySqlColumnCompiler.js +0 -26
  80. package/dialects/mysql/MySqlConnection.d.ts +0 -8
  81. package/dialects/mysql/MySqlConnection.js +0 -43
  82. package/dialects/mysql/MySqlKnexDialect.d.ts +0 -5
  83. package/dialects/mysql/MySqlKnexDialect.js +0 -17
  84. package/dialects/mysql/MySqlQueryCompiler.d.ts +0 -5
  85. package/dialects/mysql/MySqlQueryCompiler.js +0 -23
  86. package/dialects/postgresql/PostgreSqlKnexDialect.d.ts +0 -7
  87. package/dialects/postgresql/PostgreSqlKnexDialect.js +0 -20
  88. package/dialects/postgresql/PostgreSqlQueryCompiler.d.ts +0 -4
  89. package/dialects/postgresql/PostgreSqlQueryCompiler.js +0 -13
  90. package/dialects/postgresql/PostgreSqlTableCompiler.d.ts +0 -11
  91. package/dialects/postgresql/PostgreSqlTableCompiler.js +0 -89
  92. package/dialects/sqlite/BaseSqliteSchemaHelper.d.ts +0 -28
  93. package/dialects/sqlite/BaseSqliteSchemaHelper.js +0 -200
  94. package/dialects/sqlite/BetterSqliteKnexDialect.d.ts +0 -5
  95. package/dialects/sqlite/BetterSqliteKnexDialect.js +0 -15
  96. package/dialects/sqlite/LibSqlKnexDialect.d.ts +0 -11
  97. package/dialects/sqlite/LibSqlKnexDialect.js +0 -85
  98. package/dialects/sqlite/SqliteKnexDialect.d.ts +0 -8
  99. package/dialects/sqlite/SqliteKnexDialect.js +0 -67
  100. package/dialects/sqlite/SqliteTableCompiler.d.ts +0 -6
  101. package/dialects/sqlite/SqliteTableCompiler.js +0 -71
@@ -1,15 +1,12 @@
1
- import { type Knex } from 'knex';
2
- import { Connection, type AnyEntity, type Configuration, type ConnectionOptions, type EntityData, type IsolationLevel, type QueryResult, type Transaction, type TransactionEventBroadcaster, type LoggingOptions } from '@mikro-orm/core';
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: Knex;
8
- constructor(config: Configuration, options?: ConnectionOptions, type?: 'read' | 'write');
9
- abstract createKnex(): void;
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
- transactional<T>(cb: (trx: Transaction<Knex.Transaction>) => Promise<T>, options?: {
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?: Knex.Transaction;
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?: Knex.Transaction;
38
+ ctx?: ControlledTransaction<any, any>;
41
39
  eventBroadcaster?: TransactionEventBroadcaster;
42
- }): Promise<Knex.Transaction>;
43
- commit(ctx: Knex.Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
44
- rollback(ctx: Knex.Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
45
- execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(queryOrKnex: string | Knex.QueryBuilder | Knex.Raw, params?: unknown[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions): Promise<T>;
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
  }
@@ -1,37 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractSqlConnection = void 0;
4
- const knex_1 = require("knex");
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 MonkeyPatchable_1 = require("./MonkeyPatchable");
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
- constructor(config, options, type) {
16
- super(config, options, type);
17
- this.patchKnexClient();
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
- return this.client;
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.getKnex().destroy();
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.getKnex().raw('select 1');
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,77 @@ class AbstractSqlConnection extends core_1.Connection {
65
74
  }
66
75
  }
67
76
  async begin(options = {}) {
68
- if (!options.ctx) {
69
- await options.eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionStart);
70
- }
71
- const trx = await (options.ctx || this.getKnex()).transaction(null, {
72
- isolationLevel: options.isolationLevel,
73
- readOnly: options.readOnly,
74
- });
75
- if (!options.ctx) {
76
- await options.eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionStart, trx);
77
- }
78
- else {
79
- trx[parentTransactionSymbol] = options.ctx;
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
+ if (options.readOnly) {
93
+ trxBuilder = trxBuilder.setAccessMode('read only');
94
+ }
95
+ const trx = await trxBuilder.execute();
96
+ for (const query of this.platform.getBeginTransactionSQL(options)) {
97
+ this.logQuery(query);
98
+ }
99
+ await options.eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionStart, trx);
81
100
  return trx;
82
101
  }
83
102
  async commit(ctx, eventBroadcaster) {
84
- const runTrxHooks = isRootTransaction(ctx);
85
- if (runTrxHooks) {
86
- await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionCommit, ctx);
103
+ if (ctx.isRolledBack) {
104
+ return;
87
105
  }
88
- ctx.commit();
89
- await ctx.executionPromise; // https://github.com/knex/knex/issues/3847#issuecomment-626330453
90
- if (runTrxHooks) {
91
- await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionCommit, ctx);
106
+ if ('savepointName' in ctx) {
107
+ await ctx.releaseSavepoint(ctx.savepointName).execute();
108
+ this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
109
+ return;
92
110
  }
111
+ await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionCommit, ctx);
112
+ await ctx.commit().execute();
113
+ this.logQuery(this.platform.getCommitTransactionSQL());
114
+ await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionCommit, ctx);
93
115
  }
94
116
  async rollback(ctx, eventBroadcaster) {
95
- const runTrxHooks = isRootTransaction(ctx);
96
- if (runTrxHooks) {
97
- await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionRollback, ctx);
98
- }
99
- await ctx.rollback();
100
- if (runTrxHooks) {
101
- await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionRollback, ctx);
117
+ if ('savepointName' in ctx) {
118
+ await ctx.rollbackToSavepoint(ctx.savepointName).execute();
119
+ this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName));
120
+ return;
102
121
  }
122
+ await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionRollback, ctx);
123
+ await ctx.rollback().execute();
124
+ this.logQuery(this.platform.getRollbackTransactionSQL());
125
+ await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionRollback, ctx);
103
126
  }
104
- async execute(queryOrKnex, params = [], method = 'all', ctx, loggerContext) {
127
+ async execute(query, params = [], method = 'all', ctx, loggerContext) {
105
128
  await this.ensureConnection();
106
- if (core_1.Utils.isObject(queryOrKnex)) {
107
- ctx ??= (queryOrKnex.client.transacting ? queryOrKnex : null);
108
- const q = queryOrKnex.toSQL();
109
- queryOrKnex = q.sql;
110
- params = q.bindings;
111
- }
112
- queryOrKnex = this.config.get('onQuery')(queryOrKnex, params);
113
- const formatted = this.platform.formatQuery(queryOrKnex, params);
114
- const sql = this.getSql(queryOrKnex, formatted, loggerContext);
129
+ if (query instanceof query_1.NativeQueryBuilder) {
130
+ query = query.toRaw();
131
+ }
132
+ if (query instanceof core_1.RawQueryFragment) {
133
+ params = query.params;
134
+ query = query.sql;
135
+ }
136
+ query = this.config.get('onQuery')(query, params);
137
+ const formatted = this.platform.formatQuery(query, params);
138
+ const sql = this.getSql(query, formatted, loggerContext);
115
139
  return this.executeQuery(sql, async () => {
116
- const query = this.getKnex().raw(formatted);
140
+ const compiled = kysely_1.CompiledQuery.raw(formatted);
117
141
  if (ctx) {
118
- query.transacting(ctx);
142
+ const res = await ctx.executeQuery(compiled);
143
+ return this.transformRawResult(res, method);
119
144
  }
120
- const res = await query;
145
+ const res = await this.client.executeQuery(compiled);
121
146
  return this.transformRawResult(res, method);
122
- }, { query: queryOrKnex, params, ...loggerContext });
147
+ }, { query, params, ...loggerContext });
123
148
  }
124
149
  /**
125
150
  * Execute raw SQL queries from file
@@ -127,50 +152,14 @@ class AbstractSqlConnection extends core_1.Connection {
127
152
  async loadFile(path) {
128
153
  const buf = await (0, fs_extra_1.readFile)(path);
129
154
  try {
130
- await this.getKnex().raw(buf.toString());
155
+ const raw = kysely_1.CompiledQuery.raw(buf.toString());
156
+ await this.client.executeQuery(raw);
131
157
  }
132
158
  catch (e) {
133
159
  /* istanbul ignore next */
134
160
  throw this.platform.getExceptionConverter().convertException(e);
135
161
  }
136
162
  }
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
163
  getSql(query, formatted, context) {
175
164
  const logger = this.config.getLogger();
176
165
  if (!logger.isEnabled('query', context)) {
@@ -179,34 +168,20 @@ class AbstractSqlConnection extends core_1.Connection {
179
168
  if (logger.isEnabled('query-params', context)) {
180
169
  return formatted;
181
170
  }
182
- return this.getKnex().client.positionBindings(query);
171
+ return query;
183
172
  }
184
- /**
185
- * do not call `positionBindings` when there are no bindings - it was messing up with
186
- * already interpolated strings containing `?`, and escaping that was not enough to
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;
173
+ transformRawResult(res, method) {
174
+ if (method === 'get') {
175
+ return res.rows[0];
194
176
  }
195
- AbstractSqlConnection.__patched = true;
196
- Client.prototype.query = function (connection, obj) {
197
- if (typeof obj === 'string') {
198
- obj = { sql: obj };
199
- }
200
- if ((obj.bindings ?? []).length > 0) {
201
- return query.call(this, connection, obj);
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);
177
+ if (method === 'all') {
178
+ return res.rows;
179
+ }
180
+ return {
181
+ affectedRows: Number(res.numAffectedRows ?? res.rows.length),
182
+ insertId: res.insertId != null ? Number(res.insertId) : res.insertId,
183
+ row: res.rows[0],
184
+ rows: res.rows,
210
185
  };
211
186
  }
212
187
  }
@@ -1,8 +1,7 @@
1
- import type { Knex } from 'knex';
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>[]>(queryOrKnex: string | Knex.QueryBuilder | Knex.Raw, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions): Promise<T>;
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>, explicitFields?: Field<T>[], exclude?: Field<T>[], populate?: PopulateOptions<T>[], options?: {
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?: string): Field<T>[];
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<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): QueryBuilder<T, any, any, any>;
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<Knex.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 {};