@mikro-orm/sql 7.0.2 → 7.0.3-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 (86) hide show
  1. package/AbstractSqlConnection.d.ts +58 -94
  2. package/AbstractSqlConnection.js +238 -235
  3. package/AbstractSqlDriver.d.ts +155 -411
  4. package/AbstractSqlDriver.js +1937 -2061
  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/SqlEntityManager.d.ts +22 -67
  10. package/SqlEntityManager.js +38 -54
  11. package/SqlEntityRepository.d.ts +14 -14
  12. package/SqlEntityRepository.js +23 -23
  13. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
  14. package/dialects/mssql/MsSqlNativeQueryBuilder.js +194 -192
  15. package/dialects/mysql/BaseMySqlPlatform.d.ts +45 -64
  16. package/dialects/mysql/BaseMySqlPlatform.js +131 -134
  17. package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
  18. package/dialects/mysql/MySqlExceptionConverter.js +77 -91
  19. package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
  20. package/dialects/mysql/MySqlNativeQueryBuilder.js +69 -66
  21. package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -39
  22. package/dialects/mysql/MySqlSchemaHelper.js +319 -327
  23. package/dialects/oracledb/OracleDialect.d.ts +52 -81
  24. package/dialects/oracledb/OracleDialect.js +149 -155
  25. package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
  26. package/dialects/oracledb/OracleNativeQueryBuilder.js +236 -232
  27. package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +105 -108
  28. package/dialects/postgresql/BasePostgreSqlPlatform.js +350 -351
  29. package/dialects/postgresql/FullTextType.d.ts +6 -10
  30. package/dialects/postgresql/FullTextType.js +51 -51
  31. package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
  32. package/dialects/postgresql/PostgreSqlExceptionConverter.js +43 -55
  33. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
  34. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
  35. package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +82 -102
  36. package/dialects/postgresql/PostgreSqlSchemaHelper.js +683 -711
  37. package/dialects/sqlite/BaseSqliteConnection.d.ts +5 -3
  38. package/dialects/sqlite/BaseSqliteConnection.js +19 -21
  39. package/dialects/sqlite/NodeSqliteDialect.d.ts +1 -1
  40. package/dialects/sqlite/NodeSqliteDialect.js +23 -23
  41. package/dialects/sqlite/SqliteDriver.d.ts +1 -1
  42. package/dialects/sqlite/SqliteDriver.js +3 -3
  43. package/dialects/sqlite/SqliteExceptionConverter.d.ts +6 -6
  44. package/dialects/sqlite/SqliteExceptionConverter.js +51 -67
  45. package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
  46. package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
  47. package/dialects/sqlite/SqlitePlatform.d.ts +72 -63
  48. package/dialects/sqlite/SqlitePlatform.js +139 -139
  49. package/dialects/sqlite/SqliteSchemaHelper.d.ts +60 -70
  50. package/dialects/sqlite/SqliteSchemaHelper.js +520 -533
  51. package/package.json +2 -2
  52. package/plugin/index.d.ts +35 -42
  53. package/plugin/index.js +36 -43
  54. package/plugin/transformer.d.ts +94 -117
  55. package/plugin/transformer.js +881 -890
  56. package/query/ArrayCriteriaNode.d.ts +4 -4
  57. package/query/ArrayCriteriaNode.js +18 -18
  58. package/query/CriteriaNode.d.ts +25 -35
  59. package/query/CriteriaNode.js +123 -133
  60. package/query/CriteriaNodeFactory.d.ts +6 -49
  61. package/query/CriteriaNodeFactory.js +94 -97
  62. package/query/NativeQueryBuilder.d.ts +118 -118
  63. package/query/NativeQueryBuilder.js +480 -484
  64. package/query/ObjectCriteriaNode.d.ts +12 -12
  65. package/query/ObjectCriteriaNode.js +282 -298
  66. package/query/QueryBuilder.d.ts +904 -1546
  67. package/query/QueryBuilder.js +2145 -2270
  68. package/query/QueryBuilderHelper.d.ts +72 -153
  69. package/query/QueryBuilderHelper.js +1028 -1079
  70. package/query/ScalarCriteriaNode.d.ts +3 -3
  71. package/query/ScalarCriteriaNode.js +46 -53
  72. package/query/enums.d.ts +14 -14
  73. package/query/enums.js +14 -14
  74. package/query/raw.d.ts +6 -16
  75. package/query/raw.js +10 -10
  76. package/schema/DatabaseSchema.d.ts +50 -73
  77. package/schema/DatabaseSchema.js +307 -331
  78. package/schema/DatabaseTable.d.ts +73 -96
  79. package/schema/DatabaseTable.js +927 -1012
  80. package/schema/SchemaComparator.d.ts +54 -58
  81. package/schema/SchemaComparator.js +719 -745
  82. package/schema/SchemaHelper.d.ts +95 -109
  83. package/schema/SchemaHelper.js +659 -675
  84. package/schema/SqlSchemaGenerator.d.ts +58 -78
  85. package/schema/SqlSchemaGenerator.js +501 -535
  86. package/typings.d.ts +266 -380
@@ -3,243 +3,247 @@ import { QueryType } from '../../query/enums.js';
3
3
  import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
4
4
  /** @internal */
5
5
  export function markOutBindings(obj) {
6
- Object.defineProperty(obj, '__outBindings', {
7
- value: true,
8
- writable: true,
9
- configurable: true,
10
- enumerable: false,
11
- });
6
+ Object.defineProperty(obj, '__outBindings', {
7
+ value: true,
8
+ writable: true,
9
+ configurable: true,
10
+ enumerable: false,
11
+ });
12
12
  }
13
13
  /** @internal */
14
14
  export class OracleNativeQueryBuilder extends NativeQueryBuilder {
15
- as(alias) {
16
- this.wrap('(', `) ${this.platform.quoteIdentifier(alias)}`);
17
- return this;
18
- }
19
- compile() {
20
- if (!this.type) {
21
- throw new Error('No query type provided');
22
- }
23
- this.parts.length = 0;
24
- this.params.length = 0;
25
- /* v8 ignore next 3: query comment branch */
26
- if (this.options.comment) {
27
- this.parts.push(...this.options.comment.map(comment => `/* ${comment} */`));
28
- }
29
- let copy;
30
- if (this.options.onConflict && !Utils.isEmpty(Utils.asArray(this.options.data)[0])) {
31
- this.compileUpsert();
32
- } else {
33
- if (this.options.returning && Array.isArray(this.options.data) && this.options.data.length > 1) {
34
- copy = [...this.options.data];
35
- this.options.data.length = 1;
36
- }
37
- switch (this.type) {
38
- case QueryType.SELECT:
39
- case QueryType.COUNT:
40
- this.compileSelect();
41
- break;
42
- case QueryType.INSERT:
43
- this.compileInsert();
44
- break;
45
- case QueryType.UPDATE:
46
- this.compileUpdate();
47
- break;
48
- case QueryType.DELETE:
49
- this.compileDelete();
50
- break;
51
- case QueryType.TRUNCATE:
52
- this.compileTruncate();
53
- break;
54
- }
55
- this.addOnConflictClause();
56
- }
57
- if (this.options.returning) {
58
- const isUpsert = this.options.onConflict && !Utils.isEmpty(Utils.asArray(this.options.data)[0]);
59
- const prefix = isUpsert ? `${this.getTableName()}.` : '';
60
- const fields = this.options.returning.map(field => prefix + this.quote(Array.isArray(field) ? field[0] : field));
61
- const into = this.options.returning.map(field => ':out_' + (Array.isArray(field) ? field[0] : field));
62
- const outBindings = this.options.returning.map(field => {
63
- const name = 'out_' + (Array.isArray(field) ? field[0] : field);
64
- const type = Array.isArray(field) ? field[1] : 'string';
65
- return [name, type];
66
- });
67
- markOutBindings(outBindings);
68
- this.parts.push(`returning ${fields.join(', ')}`);
69
- this.parts.push(`into ${into.join(', ')}`);
70
- this.params.push(outBindings);
71
- }
72
- this.addLockClause();
73
- if (!copy) {
74
- return this.combineParts();
75
- }
76
- // multi insert with returning
77
- const sql = this.parts.join(' ');
78
- const blockLines = [];
79
- const block2Lines = [];
80
- const keys = Object.keys(copy[0]);
81
- const last = this.params[this.params.length - 1];
82
- /* v8 ignore next 3: defensive check — output bindings are always set by compile() */
83
- if (!Array.isArray(last) || !('__outBindings' in last) || !last.__outBindings) {
84
- throw new Error('Output bindings are required for multi insert with returning');
85
- }
86
- const outBindings = {};
87
- markOutBindings(outBindings);
88
- for (let i = 0; i < copy.length; i++) {
89
- const params = [];
90
- for (const key of keys) {
91
- /* v8 ignore next 3: undefined value branch in multi-insert */
92
- if (typeof copy[i][key] === 'undefined') {
93
- params.push(this.platform.usesDefaultKeyword() ? raw('default') : null);
94
- } else {
95
- params.push(copy[i][key]);
96
- }
97
- }
98
- // we need to interpolate to allow proper escaping
99
- const formatted = this.platform.formatQuery(sql, params).replaceAll(`'`, `''`);
100
- /* v8 ignore next 3: returning field type branches */
101
- const using = this.options.returning.map(field => {
102
- const name = Array.isArray(field) ? field[0] : field;
103
- const type = Array.isArray(field) ? field[1] : 'string';
104
- outBindings[`out_${name}__${i}`] = {
105
- dir: this.platform.mapToBindType('out'),
106
- type: this.platform.mapToBindType(type),
107
- };
108
- return `out :out_${name}__${i}`;
109
- });
110
- blockLines.push(` execute immediate '${formatted}' using ${using.join(', ')};`);
111
- block2Lines.push(` execute immediate '${sql}' using ${using.join(', ')};`);
112
- }
113
- const block = `begin\n${blockLines.join('\n')}\n end;`;
114
- const block2 = `begin\n${block2Lines.join('\n')}\n end;`;
115
- // save raw query without interpolation for logging,
116
- Object.defineProperty(outBindings, '__rawQuery', {
117
- value: block2,
118
- writable: true,
119
- configurable: true,
120
- enumerable: false,
121
- });
122
- this.options.data = copy;
123
- return { sql: block, params: [outBindings] };
124
- }
125
- compileTruncate() {
126
- super.compileTruncate();
127
- this.parts.push('drop all storage cascade');
128
- }
129
- combineParts() {
130
- let sql = this.parts.join(' ');
131
- const last = this.params[this.params.length - 1];
132
- if (this.options.wrap) {
133
- const [a, b] = this.options.wrap;
134
- sql = `${a}${sql}${b}`;
135
- }
136
- if (!(Array.isArray(last) && '__outBindings' in last && last.__outBindings)) {
137
- return { sql, params: this.params };
138
- }
139
- const out = this.params.pop();
140
- const outBindings = {};
141
- markOutBindings(outBindings);
142
- this.params.push(outBindings);
143
- for (const item of out) {
144
- outBindings[item[0]] = {
145
- dir: this.platform.mapToBindType('out'),
146
- type: this.platform.mapToBindType(item[1]),
147
- };
15
+ as(alias) {
16
+ this.wrap('(', `) ${this.platform.quoteIdentifier(alias)}`);
17
+ return this;
148
18
  }
149
- return { sql, params: this.params };
150
- }
151
- compileUpsert() {
152
- const clause = this.options.onConflict;
153
- const dataAsArray = Utils.asArray(this.options.data);
154
- const keys = Object.keys(dataAsArray[0]);
155
- const parts = [];
156
- for (const data of dataAsArray) {
157
- for (const key of keys) {
158
- this.params.push(data[key]);
159
- }
160
- parts.push(`select ${keys.map(k => `? as ${this.quote(k)}`).join(', ')} from dual`);
161
- }
162
- this.parts.push(`merge into ${this.getTableName()}`);
163
- this.parts.push(`using (${parts.join(' union all ')}) tsource`);
164
- /* v8 ignore next 4: RawQueryFragment conflict fields branch */
165
- if (clause.fields instanceof RawQueryFragment) {
166
- this.parts.push(clause.fields.sql);
167
- this.params.push(...clause.fields.params);
168
- } else if (clause.fields.length > 0) {
169
- const fields = clause.fields.map(field => {
170
- const col = this.quote(field);
171
- return `${this.getTableName()}.${col} = tsource.${col}`;
172
- });
173
- this.parts.push(`on (${fields.join(' and ')})`);
174
- }
175
- const sourceColumns = keys.map(field => `tsource.${this.quote(field)}`).join(', ');
176
- const destinationColumns = keys.map(field => this.quote(field)).join(', ');
177
- this.parts.push(`when not matched then insert (${destinationColumns}) values (${sourceColumns})`);
178
- if (!clause.ignore) {
179
- /* v8 ignore next: merge type branch */
180
- if (!clause.merge || Array.isArray(clause.merge)) {
181
- const mergeParts = (clause.merge || keys)
182
- .filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
183
- .filter(field => keys.includes(field)) // only reference columns present in the source data
184
- .map(column => `${this.quote(column)} = tsource.${this.quote(column)}`);
185
- /* v8 ignore next 10: empty mergeParts branch */
186
- if (mergeParts.length > 0) {
187
- this.parts.push('when matched');
188
- if (clause.where) {
189
- this.parts.push(`and ${clause.where.sql}`);
190
- this.params.push(...clause.where.params);
191
- }
192
- this.parts.push('then update set');
193
- this.parts.push(mergeParts.join(', '));
194
- }
195
- } /* v8 ignore start: object-form merge branch */ else if (typeof clause.merge === 'object') {
196
- this.parts.push('when matched');
197
- if (clause.where) {
198
- this.parts.push(`and ${clause.where.sql}`);
199
- this.params.push(...clause.where.params);
200
- }
201
- this.parts.push('then update set');
202
- const parts = Object.entries(clause.merge).map(([key, value]) => {
203
- this.params.push(value);
204
- return `${this.getTableName()}.${this.quote(key)} = ?`;
19
+ compile() {
20
+ if (!this.type) {
21
+ throw new Error('No query type provided');
22
+ }
23
+ this.parts.length = 0;
24
+ this.params.length = 0;
25
+ /* v8 ignore next 3: query comment branch */
26
+ if (this.options.comment) {
27
+ this.parts.push(...this.options.comment.map(comment => `/* ${comment} */`));
28
+ }
29
+ let copy;
30
+ if (this.options.onConflict && !Utils.isEmpty(Utils.asArray(this.options.data)[0])) {
31
+ this.compileUpsert();
32
+ }
33
+ else {
34
+ if (this.options.returning && Array.isArray(this.options.data) && this.options.data.length > 1) {
35
+ copy = [...this.options.data];
36
+ this.options.data.length = 1;
37
+ }
38
+ switch (this.type) {
39
+ case QueryType.SELECT:
40
+ case QueryType.COUNT:
41
+ this.compileSelect();
42
+ break;
43
+ case QueryType.INSERT:
44
+ this.compileInsert();
45
+ break;
46
+ case QueryType.UPDATE:
47
+ this.compileUpdate();
48
+ break;
49
+ case QueryType.DELETE:
50
+ this.compileDelete();
51
+ break;
52
+ case QueryType.TRUNCATE:
53
+ this.compileTruncate();
54
+ break;
55
+ }
56
+ this.addOnConflictClause();
57
+ }
58
+ if (this.options.returning) {
59
+ const isUpsert = this.options.onConflict && !Utils.isEmpty(Utils.asArray(this.options.data)[0]);
60
+ const prefix = isUpsert ? `${this.getTableName()}.` : '';
61
+ const fields = this.options.returning.map(field => prefix + this.quote(Array.isArray(field) ? field[0] : field));
62
+ const into = this.options.returning.map(field => ':out_' + (Array.isArray(field) ? field[0] : field));
63
+ const outBindings = this.options.returning.map(field => {
64
+ const name = 'out_' + (Array.isArray(field) ? field[0] : field);
65
+ const type = Array.isArray(field) ? field[1] : 'string';
66
+ return [name, type];
67
+ });
68
+ markOutBindings(outBindings);
69
+ this.parts.push(`returning ${fields.join(', ')}`);
70
+ this.parts.push(`into ${into.join(', ')}`);
71
+ this.params.push(outBindings);
72
+ }
73
+ this.addLockClause();
74
+ if (!copy) {
75
+ return this.combineParts();
76
+ }
77
+ // multi insert with returning
78
+ const sql = this.parts.join(' ');
79
+ const blockLines = [];
80
+ const block2Lines = [];
81
+ const keys = Object.keys(copy[0]);
82
+ const last = this.params[this.params.length - 1];
83
+ /* v8 ignore next 3: defensive check — output bindings are always set by compile() */
84
+ if (!Array.isArray(last) || !('__outBindings' in last) || !last.__outBindings) {
85
+ throw new Error('Output bindings are required for multi insert with returning');
86
+ }
87
+ const outBindings = {};
88
+ markOutBindings(outBindings);
89
+ for (let i = 0; i < copy.length; i++) {
90
+ const params = [];
91
+ for (const key of keys) {
92
+ /* v8 ignore next 3: undefined value branch in multi-insert */
93
+ if (typeof copy[i][key] === 'undefined') {
94
+ params.push(this.platform.usesDefaultKeyword() ? raw('default') : null);
95
+ }
96
+ else {
97
+ params.push(copy[i][key]);
98
+ }
99
+ }
100
+ // we need to interpolate to allow proper escaping
101
+ const formatted = this.platform.formatQuery(sql, params).replaceAll(`'`, `''`);
102
+ /* v8 ignore next 3: returning field type branches */
103
+ const using = this.options.returning.map(field => {
104
+ const name = Array.isArray(field) ? field[0] : field;
105
+ const type = Array.isArray(field) ? field[1] : 'string';
106
+ outBindings[`out_${name}__${i}`] = {
107
+ dir: this.platform.mapToBindType('out'),
108
+ type: this.platform.mapToBindType(type),
109
+ };
110
+ return `out :out_${name}__${i}`;
111
+ });
112
+ blockLines.push(` execute immediate '${formatted}' using ${using.join(', ')};`);
113
+ block2Lines.push(` execute immediate '${sql}' using ${using.join(', ')};`);
114
+ }
115
+ const block = `begin\n${blockLines.join('\n')}\n end;`;
116
+ const block2 = `begin\n${block2Lines.join('\n')}\n end;`;
117
+ // save raw query without interpolation for logging,
118
+ Object.defineProperty(outBindings, '__rawQuery', {
119
+ value: block2,
120
+ writable: true,
121
+ configurable: true,
122
+ enumerable: false,
205
123
  });
206
- this.parts.push(parts.join(', '));
207
- }
208
- /* v8 ignore stop */
209
- }
210
- }
211
- compileSelect() {
212
- this.parts.push('select');
213
- this.addHintComment();
214
- this.parts.push(`${this.getFields()} from ${this.getTableName()}`);
215
- if (this.options.joins) {
216
- for (const join of this.options.joins) {
217
- this.parts.push(join.sql);
218
- this.params.push(...join.params);
219
- }
220
- }
221
- if (this.options.where?.sql.trim()) {
222
- this.parts.push(`where ${this.options.where.sql}`);
223
- this.params.push(...this.options.where.params);
224
- }
225
- if (this.options.groupBy) {
226
- const fields = this.options.groupBy.map(field => this.quote(field));
227
- this.parts.push(`group by ${fields.join(', ')}`);
228
- }
229
- if (this.options.having) {
230
- this.parts.push(`having ${this.options.having.sql}`);
231
- this.params.push(...this.options.having.params);
232
- }
233
- if (this.options.orderBy) {
234
- this.parts.push(`order by ${this.options.orderBy}`);
235
- }
236
- if (this.options.offset != null) {
237
- this.parts.push(`offset ? rows`);
238
- this.params.push(this.options.offset);
124
+ this.options.data = copy;
125
+ return { sql: block, params: [outBindings] };
126
+ }
127
+ compileTruncate() {
128
+ super.compileTruncate();
129
+ this.parts.push('drop all storage cascade');
130
+ }
131
+ combineParts() {
132
+ let sql = this.parts.join(' ');
133
+ const last = this.params[this.params.length - 1];
134
+ if (this.options.wrap) {
135
+ const [a, b] = this.options.wrap;
136
+ sql = `${a}${sql}${b}`;
137
+ }
138
+ if (!(Array.isArray(last) && '__outBindings' in last && last.__outBindings)) {
139
+ return { sql, params: this.params };
140
+ }
141
+ const out = this.params.pop();
142
+ const outBindings = {};
143
+ markOutBindings(outBindings);
144
+ this.params.push(outBindings);
145
+ for (const item of out) {
146
+ outBindings[item[0]] = {
147
+ dir: this.platform.mapToBindType('out'),
148
+ type: this.platform.mapToBindType(item[1]),
149
+ };
150
+ }
151
+ return { sql, params: this.params };
152
+ }
153
+ compileUpsert() {
154
+ const clause = this.options.onConflict;
155
+ const dataAsArray = Utils.asArray(this.options.data);
156
+ const keys = Object.keys(dataAsArray[0]);
157
+ const parts = [];
158
+ for (const data of dataAsArray) {
159
+ for (const key of keys) {
160
+ this.params.push(data[key]);
161
+ }
162
+ parts.push(`select ${keys.map(k => `? as ${this.quote(k)}`).join(', ')} from dual`);
163
+ }
164
+ this.parts.push(`merge into ${this.getTableName()}`);
165
+ this.parts.push(`using (${parts.join(' union all ')}) tsource`);
166
+ /* v8 ignore next 4: RawQueryFragment conflict fields branch */
167
+ if (clause.fields instanceof RawQueryFragment) {
168
+ this.parts.push(clause.fields.sql);
169
+ this.params.push(...clause.fields.params);
170
+ }
171
+ else if (clause.fields.length > 0) {
172
+ const fields = clause.fields.map(field => {
173
+ const col = this.quote(field);
174
+ return `${this.getTableName()}.${col} = tsource.${col}`;
175
+ });
176
+ this.parts.push(`on (${fields.join(' and ')})`);
177
+ }
178
+ const sourceColumns = keys.map(field => `tsource.${this.quote(field)}`).join(', ');
179
+ const destinationColumns = keys.map(field => this.quote(field)).join(', ');
180
+ this.parts.push(`when not matched then insert (${destinationColumns}) values (${sourceColumns})`);
181
+ if (!clause.ignore) {
182
+ /* v8 ignore next: merge type branch */
183
+ if (!clause.merge || Array.isArray(clause.merge)) {
184
+ const mergeParts = (clause.merge || keys)
185
+ .filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
186
+ .filter((field) => keys.includes(field)) // only reference columns present in the source data
187
+ .map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
188
+ /* v8 ignore next 10: empty mergeParts branch */
189
+ if (mergeParts.length > 0) {
190
+ this.parts.push('when matched');
191
+ if (clause.where) {
192
+ this.parts.push(`and ${clause.where.sql}`);
193
+ this.params.push(...clause.where.params);
194
+ }
195
+ this.parts.push('then update set');
196
+ this.parts.push(mergeParts.join(', '));
197
+ }
198
+ } /* v8 ignore start: object-form merge branch */
199
+ else if (typeof clause.merge === 'object') {
200
+ this.parts.push('when matched');
201
+ if (clause.where) {
202
+ this.parts.push(`and ${clause.where.sql}`);
203
+ this.params.push(...clause.where.params);
204
+ }
205
+ this.parts.push('then update set');
206
+ const parts = Object.entries(clause.merge).map(([key, value]) => {
207
+ this.params.push(value);
208
+ return `${this.getTableName()}.${this.quote(key)} = ?`;
209
+ });
210
+ this.parts.push(parts.join(', '));
211
+ }
212
+ /* v8 ignore stop */
213
+ }
239
214
  }
240
- if (this.options.limit != null) {
241
- this.parts.push(`fetch next ? rows only`);
242
- this.params.push(this.options.limit);
215
+ compileSelect() {
216
+ this.parts.push('select');
217
+ this.addHintComment();
218
+ this.parts.push(`${this.getFields()} from ${this.getTableName()}`);
219
+ if (this.options.joins) {
220
+ for (const join of this.options.joins) {
221
+ this.parts.push(join.sql);
222
+ this.params.push(...join.params);
223
+ }
224
+ }
225
+ if (this.options.where?.sql.trim()) {
226
+ this.parts.push(`where ${this.options.where.sql}`);
227
+ this.params.push(...this.options.where.params);
228
+ }
229
+ if (this.options.groupBy) {
230
+ const fields = this.options.groupBy.map(field => this.quote(field));
231
+ this.parts.push(`group by ${fields.join(', ')}`);
232
+ }
233
+ if (this.options.having) {
234
+ this.parts.push(`having ${this.options.having.sql}`);
235
+ this.params.push(...this.options.having.params);
236
+ }
237
+ if (this.options.orderBy) {
238
+ this.parts.push(`order by ${this.options.orderBy}`);
239
+ }
240
+ if (this.options.offset != null) {
241
+ this.parts.push(`offset ? rows`);
242
+ this.params.push(this.options.offset);
243
+ }
244
+ if (this.options.limit != null) {
245
+ this.parts.push(`fetch next ? rows only`);
246
+ this.params.push(this.options.limit);
247
+ }
243
248
  }
244
- }
245
249
  }