@mikro-orm/sql 7.0.4 → 7.0.5-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.
Files changed (87) hide show
  1. package/AbstractSqlConnection.d.ts +58 -94
  2. package/AbstractSqlConnection.js +238 -235
  3. package/AbstractSqlDriver.d.ts +155 -410
  4. package/AbstractSqlDriver.js +1941 -2064
  5. package/AbstractSqlPlatform.d.ts +73 -83
  6. package/AbstractSqlPlatform.js +158 -162
  7. package/PivotCollectionPersister.d.ts +15 -33
  8. package/PivotCollectionPersister.js +160 -158
  9. package/README.md +1 -1
  10. package/SqlEntityManager.d.ts +22 -67
  11. package/SqlEntityManager.js +38 -54
  12. package/SqlEntityRepository.d.ts +14 -14
  13. package/SqlEntityRepository.js +23 -23
  14. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
  15. package/dialects/mssql/MsSqlNativeQueryBuilder.js +194 -192
  16. package/dialects/mysql/BaseMySqlPlatform.d.ts +45 -64
  17. package/dialects/mysql/BaseMySqlPlatform.js +131 -134
  18. package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
  19. package/dialects/mysql/MySqlExceptionConverter.js +77 -91
  20. package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
  21. package/dialects/mysql/MySqlNativeQueryBuilder.js +69 -66
  22. package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -39
  23. package/dialects/mysql/MySqlSchemaHelper.js +319 -327
  24. package/dialects/oracledb/OracleDialect.d.ts +52 -81
  25. package/dialects/oracledb/OracleDialect.js +149 -155
  26. package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
  27. package/dialects/oracledb/OracleNativeQueryBuilder.js +236 -232
  28. package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +106 -109
  29. package/dialects/postgresql/BasePostgreSqlPlatform.js +353 -354
  30. package/dialects/postgresql/FullTextType.d.ts +6 -10
  31. package/dialects/postgresql/FullTextType.js +51 -51
  32. package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
  33. package/dialects/postgresql/PostgreSqlExceptionConverter.js +43 -55
  34. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
  35. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
  36. package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +82 -102
  37. package/dialects/postgresql/PostgreSqlSchemaHelper.js +705 -733
  38. package/dialects/sqlite/BaseSqliteConnection.d.ts +5 -3
  39. package/dialects/sqlite/BaseSqliteConnection.js +19 -21
  40. package/dialects/sqlite/NodeSqliteDialect.d.ts +1 -1
  41. package/dialects/sqlite/NodeSqliteDialect.js +23 -23
  42. package/dialects/sqlite/SqliteDriver.d.ts +1 -1
  43. package/dialects/sqlite/SqliteDriver.js +3 -3
  44. package/dialects/sqlite/SqliteExceptionConverter.d.ts +6 -6
  45. package/dialects/sqlite/SqliteExceptionConverter.js +51 -67
  46. package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
  47. package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
  48. package/dialects/sqlite/SqlitePlatform.d.ts +72 -63
  49. package/dialects/sqlite/SqlitePlatform.js +139 -139
  50. package/dialects/sqlite/SqliteSchemaHelper.d.ts +60 -70
  51. package/dialects/sqlite/SqliteSchemaHelper.js +520 -533
  52. package/package.json +2 -2
  53. package/plugin/index.d.ts +35 -42
  54. package/plugin/index.js +36 -43
  55. package/plugin/transformer.d.ts +94 -117
  56. package/plugin/transformer.js +881 -890
  57. package/query/ArrayCriteriaNode.d.ts +4 -4
  58. package/query/ArrayCriteriaNode.js +18 -18
  59. package/query/CriteriaNode.d.ts +25 -35
  60. package/query/CriteriaNode.js +123 -133
  61. package/query/CriteriaNodeFactory.d.ts +6 -49
  62. package/query/CriteriaNodeFactory.js +94 -97
  63. package/query/NativeQueryBuilder.d.ts +118 -118
  64. package/query/NativeQueryBuilder.js +480 -484
  65. package/query/ObjectCriteriaNode.d.ts +12 -12
  66. package/query/ObjectCriteriaNode.js +282 -298
  67. package/query/QueryBuilder.d.ts +905 -1557
  68. package/query/QueryBuilder.js +2192 -2322
  69. package/query/QueryBuilderHelper.d.ts +72 -153
  70. package/query/QueryBuilderHelper.js +1028 -1079
  71. package/query/ScalarCriteriaNode.d.ts +3 -3
  72. package/query/ScalarCriteriaNode.js +46 -53
  73. package/query/enums.d.ts +14 -14
  74. package/query/enums.js +14 -14
  75. package/query/raw.d.ts +6 -16
  76. package/query/raw.js +10 -10
  77. package/schema/DatabaseSchema.d.ts +50 -73
  78. package/schema/DatabaseSchema.js +307 -331
  79. package/schema/DatabaseTable.d.ts +73 -96
  80. package/schema/DatabaseTable.js +927 -1012
  81. package/schema/SchemaComparator.d.ts +66 -70
  82. package/schema/SchemaComparator.js +740 -766
  83. package/schema/SchemaHelper.d.ts +95 -109
  84. package/schema/SchemaHelper.js +659 -675
  85. package/schema/SqlSchemaGenerator.d.ts +58 -78
  86. package/schema/SqlSchemaGenerator.js +501 -535
  87. package/typings.d.ts +266 -380
@@ -1,257 +1,260 @@
1
1
  import { CompiledQuery, Kysely } from 'kysely';
2
- import { Connection, EventType, RawQueryFragment, Utils } from '@mikro-orm/core';
2
+ import { Connection, EventType, RawQueryFragment, Utils, } from '@mikro-orm/core';
3
3
  import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
4
4
  /** Base class for SQL database connections, built on top of Kysely. */
5
5
  export class AbstractSqlConnection extends Connection {
6
- #client;
7
- /** Establishes the database connection and runs the onConnect hook. */
8
- async connect(options) {
9
- await this.initClient();
10
- this.connected = true;
11
- if (options?.skipOnConnect !== true) {
12
- await this.onConnect();
13
- }
14
- }
15
- /** Initializes the Kysely client from driver options or a user-provided Kysely instance. */
16
- createKysely() {
17
- let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');
18
- if (typeof driverOptions === 'function') {
19
- driverOptions = driverOptions();
20
- }
21
- if (driverOptions instanceof Kysely) {
22
- this.logger.log('info', 'Reusing Kysely client provided via `driverOptions`');
23
- this.#client = driverOptions;
24
- } else if ('createDriver' in driverOptions) {
25
- this.logger.log('info', 'Reusing Kysely dialect provided via `driverOptions`');
26
- this.#client = new Kysely({ dialect: driverOptions });
27
- } else {
28
- const dialect = this.createKyselyDialect(driverOptions);
29
- if (dialect instanceof Promise) {
30
- return dialect.then(d => {
31
- this.#client = new Kysely({ dialect: d });
32
- });
33
- }
34
- this.#client = new Kysely({ dialect });
35
- }
36
- }
37
- /**
38
- * @inheritDoc
39
- */
40
- async close(force) {
41
- await super.close(force);
42
- await this.#client?.destroy();
43
- this.connected = false;
44
- this.#client = undefined;
45
- }
46
- /**
47
- * @inheritDoc
48
- */
49
- async isConnected() {
50
- const check = await this.checkConnection();
51
- return check.ok;
52
- }
53
- /**
54
- * @inheritDoc
55
- */
56
- async checkConnection() {
57
- if (!this.connected) {
58
- return { ok: false, reason: 'Connection not established' };
59
- }
60
- try {
61
- await this.getClient().executeQuery(CompiledQuery.raw('select 1'));
62
- return { ok: true };
63
- } catch (error) {
64
- return { ok: false, reason: error.message, error };
65
- }
66
- }
67
- /** Returns the underlying Kysely client, creating it synchronously if needed. */
68
- getClient() {
69
- if (!this.#client) {
70
- const maybePromise = this.createKysely();
71
- /* v8 ignore next */
72
- if (maybePromise instanceof Promise) {
73
- throw new Error(
74
- 'Current driver requires async initialization, use `MikroORM.init()` instead of the constructor',
75
- );
76
- }
77
- }
78
- return this.#client;
79
- }
80
- /** Ensures the Kysely client is initialized, creating it asynchronously if needed. */
81
- async initClient() {
82
- if (!this.#client) {
83
- await this.createKysely();
6
+ #client;
7
+ /** Establishes the database connection and runs the onConnect hook. */
8
+ async connect(options) {
9
+ await this.initClient();
10
+ this.connected = true;
11
+ if (options?.skipOnConnect !== true) {
12
+ await this.onConnect();
13
+ }
84
14
  }
85
- }
86
- /** Executes a callback within a transaction, committing on success and rolling back on error. */
87
- async transactional(cb, options = {}) {
88
- const trx = await this.begin(options);
89
- try {
90
- const ret = await cb(trx);
91
- await this.commit(trx, options.eventBroadcaster, options.loggerContext);
92
- return ret;
93
- } catch (error) {
94
- await this.rollback(trx, options.eventBroadcaster, options.loggerContext);
95
- throw error;
15
+ /** Initializes the Kysely client from driver options or a user-provided Kysely instance. */
16
+ createKysely() {
17
+ let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');
18
+ if (typeof driverOptions === 'function') {
19
+ driverOptions = driverOptions();
20
+ }
21
+ if (driverOptions instanceof Kysely) {
22
+ this.logger.log('info', 'Reusing Kysely client provided via `driverOptions`');
23
+ this.#client = driverOptions;
24
+ }
25
+ else if ('createDriver' in driverOptions) {
26
+ this.logger.log('info', 'Reusing Kysely dialect provided via `driverOptions`');
27
+ this.#client = new Kysely({ dialect: driverOptions });
28
+ }
29
+ else {
30
+ const dialect = this.createKyselyDialect(driverOptions);
31
+ if (dialect instanceof Promise) {
32
+ return dialect.then(d => {
33
+ this.#client = new Kysely({ dialect: d });
34
+ });
35
+ }
36
+ this.#client = new Kysely({ dialect });
37
+ }
96
38
  }
97
- }
98
- /** Begins a new transaction or creates a savepoint if a transaction context already exists. */
99
- async begin(options = {}) {
100
- if (options.ctx) {
101
- const ctx = options.ctx;
102
- await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart, ctx);
103
- ctx.index ??= 0;
104
- const savepointName = `trx${ctx.index + 1}`;
105
- const trx = await options.ctx.savepoint(savepointName).execute();
106
- Reflect.defineProperty(trx, 'index', { value: ctx.index + 1 });
107
- Reflect.defineProperty(trx, 'savepointName', { value: savepointName });
108
- this.logQuery(this.platform.getSavepointSQL(savepointName), options.loggerContext);
109
- await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
110
- return trx;
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ async close(force) {
43
+ await super.close(force);
44
+ await this.#client?.destroy();
45
+ this.connected = false;
46
+ this.#client = undefined;
111
47
  }
112
- await this.ensureConnection();
113
- await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart);
114
- let trxBuilder = this.getClient().startTransaction();
115
- if (options.isolationLevel) {
116
- trxBuilder = trxBuilder.setIsolationLevel(options.isolationLevel);
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ async isConnected() {
52
+ const check = await this.checkConnection();
53
+ return check.ok;
117
54
  }
118
- if (options.readOnly) {
119
- trxBuilder = trxBuilder.setAccessMode('read only');
55
+ /**
56
+ * @inheritDoc
57
+ */
58
+ async checkConnection() {
59
+ if (!this.connected) {
60
+ return { ok: false, reason: 'Connection not established' };
61
+ }
62
+ try {
63
+ await this.getClient().executeQuery(CompiledQuery.raw('select 1'));
64
+ return { ok: true };
65
+ }
66
+ catch (error) {
67
+ return { ok: false, reason: error.message, error };
68
+ }
120
69
  }
121
- const trx = await trxBuilder.execute();
122
- if (options.ctx) {
123
- const ctx = options.ctx;
124
- ctx.index ??= 0;
125
- const savepointName = `trx${ctx.index + 1}`;
126
- Reflect.defineProperty(trx, 'index', { value: ctx.index + 1 });
127
- Reflect.defineProperty(trx, 'savepointName', { value: savepointName });
128
- this.logQuery(this.platform.getSavepointSQL(savepointName), options.loggerContext);
129
- } else {
130
- for (const query of this.platform.getBeginTransactionSQL(options)) {
131
- this.logQuery(query, options.loggerContext);
132
- }
70
+ /** Returns the underlying Kysely client, creating it synchronously if needed. */
71
+ getClient() {
72
+ if (!this.#client) {
73
+ const maybePromise = this.createKysely();
74
+ /* v8 ignore next */
75
+ if (maybePromise instanceof Promise) {
76
+ throw new Error('Current driver requires async initialization, use `MikroORM.init()` instead of the constructor');
77
+ }
78
+ }
79
+ return this.#client;
133
80
  }
134
- await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
135
- return trx;
136
- }
137
- /** Commits the transaction or releases the savepoint. */
138
- async commit(ctx, eventBroadcaster, loggerContext) {
139
- if (ctx.isRolledBack) {
140
- return;
81
+ /** Ensures the Kysely client is initialized, creating it asynchronously if needed. */
82
+ async initClient() {
83
+ if (!this.#client) {
84
+ await this.createKysely();
85
+ }
141
86
  }
142
- await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionCommit, ctx);
143
- if ('savepointName' in ctx) {
144
- await ctx.releaseSavepoint(ctx.savepointName).execute();
145
- this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName), loggerContext);
146
- } else {
147
- await ctx.commit().execute();
148
- this.logQuery(this.platform.getCommitTransactionSQL(), loggerContext);
87
+ /** Executes a callback within a transaction, committing on success and rolling back on error. */
88
+ async transactional(cb, options = {}) {
89
+ const trx = await this.begin(options);
90
+ try {
91
+ const ret = await cb(trx);
92
+ await this.commit(trx, options.eventBroadcaster, options.loggerContext);
93
+ return ret;
94
+ }
95
+ catch (error) {
96
+ await this.rollback(trx, options.eventBroadcaster, options.loggerContext);
97
+ throw error;
98
+ }
149
99
  }
150
- await eventBroadcaster?.dispatchEvent(EventType.afterTransactionCommit, ctx);
151
- }
152
- /** Rolls back the transaction or rolls back to the savepoint. */
153
- async rollback(ctx, eventBroadcaster, loggerContext) {
154
- await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
155
- if ('savepointName' in ctx) {
156
- await ctx.rollbackToSavepoint(ctx.savepointName).execute();
157
- this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName), loggerContext);
158
- } else {
159
- await ctx.rollback().execute();
160
- this.logQuery(this.platform.getRollbackTransactionSQL(), loggerContext);
100
+ /** Begins a new transaction or creates a savepoint if a transaction context already exists. */
101
+ async begin(options = {}) {
102
+ if (options.ctx) {
103
+ const ctx = options.ctx;
104
+ await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart, ctx);
105
+ ctx.index ??= 0;
106
+ const savepointName = `trx${ctx.index + 1}`;
107
+ const trx = await options.ctx.savepoint(savepointName).execute();
108
+ Reflect.defineProperty(trx, 'index', { value: ctx.index + 1 });
109
+ Reflect.defineProperty(trx, 'savepointName', { value: savepointName });
110
+ this.logQuery(this.platform.getSavepointSQL(savepointName), options.loggerContext);
111
+ await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
112
+ return trx;
113
+ }
114
+ await this.ensureConnection();
115
+ await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart);
116
+ let trxBuilder = this.getClient().startTransaction();
117
+ if (options.isolationLevel) {
118
+ trxBuilder = trxBuilder.setIsolationLevel(options.isolationLevel);
119
+ }
120
+ if (options.readOnly) {
121
+ trxBuilder = trxBuilder.setAccessMode('read only');
122
+ }
123
+ const trx = await trxBuilder.execute();
124
+ if (options.ctx) {
125
+ const ctx = options.ctx;
126
+ ctx.index ??= 0;
127
+ const savepointName = `trx${ctx.index + 1}`;
128
+ Reflect.defineProperty(trx, 'index', { value: ctx.index + 1 });
129
+ Reflect.defineProperty(trx, 'savepointName', { value: savepointName });
130
+ this.logQuery(this.platform.getSavepointSQL(savepointName), options.loggerContext);
131
+ }
132
+ else {
133
+ for (const query of this.platform.getBeginTransactionSQL(options)) {
134
+ this.logQuery(query, options.loggerContext);
135
+ }
136
+ }
137
+ await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
138
+ return trx;
161
139
  }
162
- await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
163
- }
164
- prepareQuery(query, params = []) {
165
- if (query instanceof NativeQueryBuilder) {
166
- query = query.toRaw();
140
+ /** Commits the transaction or releases the savepoint. */
141
+ async commit(ctx, eventBroadcaster, loggerContext) {
142
+ if (ctx.isRolledBack) {
143
+ return;
144
+ }
145
+ await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionCommit, ctx);
146
+ if ('savepointName' in ctx) {
147
+ await ctx.releaseSavepoint(ctx.savepointName).execute();
148
+ this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName), loggerContext);
149
+ }
150
+ else {
151
+ await ctx.commit().execute();
152
+ this.logQuery(this.platform.getCommitTransactionSQL(), loggerContext);
153
+ }
154
+ await eventBroadcaster?.dispatchEvent(EventType.afterTransactionCommit, ctx);
167
155
  }
168
- if (query instanceof RawQueryFragment) {
169
- params = query.params;
170
- query = query.sql;
156
+ /** Rolls back the transaction or rolls back to the savepoint. */
157
+ async rollback(ctx, eventBroadcaster, loggerContext) {
158
+ await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
159
+ if ('savepointName' in ctx) {
160
+ await ctx.rollbackToSavepoint(ctx.savepointName).execute();
161
+ this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName), loggerContext);
162
+ }
163
+ else {
164
+ await ctx.rollback().execute();
165
+ this.logQuery(this.platform.getRollbackTransactionSQL(), loggerContext);
166
+ }
167
+ await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
171
168
  }
172
- query = this.config.get('onQuery')(query, params);
173
- const formatted = this.platform.formatQuery(query, params);
174
- return { query, params, formatted };
175
- }
176
- /** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */
177
- async execute(query, params = [], method = 'all', ctx, loggerContext) {
178
- await this.ensureConnection();
179
- const q = this.prepareQuery(query, params);
180
- const sql = this.getSql(q.query, q.formatted, loggerContext);
181
- return this.executeQuery(
182
- sql,
183
- async () => {
184
- const compiled = CompiledQuery.raw(q.formatted);
185
- const res = await (ctx ?? this.#client).executeQuery(compiled);
186
- return this.transformRawResult(res, method);
187
- },
188
- { ...q, ...loggerContext },
189
- );
190
- }
191
- /** Executes a SQL query and returns an async iterable that yields results row by row. */
192
- async *stream(query, params = [], ctx, loggerContext) {
193
- await this.ensureConnection();
194
- const q = this.prepareQuery(query, params);
195
- const sql = this.getSql(q.query, q.formatted, loggerContext);
196
- // construct the compiled query manually with `kind: 'SelectQueryNode'` to avoid sqlite validation for select queries when streaming
197
- const compiled = {
198
- query: {
199
- kind: 'SelectQueryNode',
200
- },
201
- sql: q.formatted,
202
- parameters: [],
203
- };
204
- try {
205
- const res = (ctx ?? this.getClient()).getExecutor().stream(compiled, 1);
206
- this.logQuery(sql, {
207
- sql,
208
- params,
209
- ...loggerContext,
210
- affected: Utils.isPlainObject(res) ? res.affectedRows : undefined,
211
- });
212
- for await (const items of res) {
213
- for (const row of this.transformRawResult(items, 'all')) {
214
- yield row;
215
- }
216
- }
217
- } catch (e) {
218
- this.logQuery(sql, { sql, params, ...loggerContext, level: 'error' });
219
- throw e;
169
+ prepareQuery(query, params = []) {
170
+ if (query instanceof NativeQueryBuilder) {
171
+ query = query.toRaw();
172
+ }
173
+ if (query instanceof RawQueryFragment) {
174
+ params = query.params;
175
+ query = query.sql;
176
+ }
177
+ query = this.config.get('onQuery')(query, params);
178
+ const formatted = this.platform.formatQuery(query, params);
179
+ return { query, params, formatted };
220
180
  }
221
- }
222
- /** @inheritDoc */
223
- async executeDump(dump) {
224
- await this.ensureConnection();
225
- try {
226
- const raw = CompiledQuery.raw(dump);
227
- await this.getClient().executeQuery(raw);
228
- } catch (e) {
229
- /* v8 ignore next */
230
- throw this.platform.getExceptionConverter().convertException(e);
181
+ /** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */
182
+ async execute(query, params = [], method = 'all', ctx, loggerContext) {
183
+ await this.ensureConnection();
184
+ const q = this.prepareQuery(query, params);
185
+ const sql = this.getSql(q.query, q.formatted, loggerContext);
186
+ return this.executeQuery(sql, async () => {
187
+ const compiled = CompiledQuery.raw(q.formatted);
188
+ const res = await (ctx ?? this.#client).executeQuery(compiled);
189
+ return this.transformRawResult(res, method);
190
+ }, { ...q, ...loggerContext });
231
191
  }
232
- }
233
- getSql(query, formatted, context) {
234
- const logger = this.config.getLogger();
235
- if (!logger.isEnabled('query', context)) {
236
- return query;
192
+ /** Executes a SQL query and returns an async iterable that yields results row by row. */
193
+ async *stream(query, params = [], ctx, loggerContext) {
194
+ await this.ensureConnection();
195
+ const q = this.prepareQuery(query, params);
196
+ const sql = this.getSql(q.query, q.formatted, loggerContext);
197
+ // construct the compiled query manually with `kind: 'SelectQueryNode'` to avoid sqlite validation for select queries when streaming
198
+ const compiled = {
199
+ query: {
200
+ kind: 'SelectQueryNode',
201
+ },
202
+ sql: q.formatted,
203
+ parameters: [],
204
+ };
205
+ try {
206
+ const res = (ctx ?? this.getClient()).getExecutor().stream(compiled, 1);
207
+ this.logQuery(sql, {
208
+ sql,
209
+ params,
210
+ ...loggerContext,
211
+ affected: Utils.isPlainObject(res) ? res.affectedRows : undefined,
212
+ });
213
+ for await (const items of res) {
214
+ for (const row of this.transformRawResult(items, 'all')) {
215
+ yield row;
216
+ }
217
+ }
218
+ }
219
+ catch (e) {
220
+ this.logQuery(sql, { sql, params, ...loggerContext, level: 'error' });
221
+ throw e;
222
+ }
237
223
  }
238
- if (logger.isEnabled('query-params', context)) {
239
- return formatted;
224
+ /** @inheritDoc */
225
+ async executeDump(dump) {
226
+ await this.ensureConnection();
227
+ try {
228
+ const raw = CompiledQuery.raw(dump);
229
+ await this.getClient().executeQuery(raw);
230
+ }
231
+ catch (e) {
232
+ /* v8 ignore next */
233
+ throw this.platform.getExceptionConverter().convertException(e);
234
+ }
240
235
  }
241
- return query;
242
- }
243
- transformRawResult(res, method) {
244
- if (method === 'get') {
245
- return res.rows[0];
236
+ getSql(query, formatted, context) {
237
+ const logger = this.config.getLogger();
238
+ if (!logger.isEnabled('query', context)) {
239
+ return query;
240
+ }
241
+ if (logger.isEnabled('query-params', context)) {
242
+ return formatted;
243
+ }
244
+ return query;
246
245
  }
247
- if (method === 'all') {
248
- return res.rows;
246
+ transformRawResult(res, method) {
247
+ if (method === 'get') {
248
+ return res.rows[0];
249
+ }
250
+ if (method === 'all') {
251
+ return res.rows;
252
+ }
253
+ return {
254
+ affectedRows: Number(res.numAffectedRows ?? res.rows.length),
255
+ insertId: res.insertId != null ? Number(res.insertId) : res.insertId,
256
+ row: res.rows[0],
257
+ rows: res.rows,
258
+ };
249
259
  }
250
- return {
251
- affectedRows: Number(res.numAffectedRows ?? res.rows.length),
252
- insertId: res.insertId != null ? Number(res.insertId) : res.insertId,
253
- row: res.rows[0],
254
- rows: res.rows,
255
- };
256
- }
257
260
  }