@mikro-orm/sql 7.0.4-dev.8 → 7.0.4
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 +94 -58
- package/AbstractSqlConnection.js +235 -238
- package/AbstractSqlDriver.d.ts +410 -155
- package/AbstractSqlDriver.js +2064 -1941
- package/AbstractSqlPlatform.d.ts +83 -73
- package/AbstractSqlPlatform.js +162 -158
- package/PivotCollectionPersister.d.ts +33 -15
- package/PivotCollectionPersister.js +158 -160
- package/README.md +1 -1
- package/SqlEntityManager.d.ts +67 -22
- package/SqlEntityManager.js +54 -38
- package/SqlEntityRepository.d.ts +14 -14
- package/SqlEntityRepository.js +23 -23
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +192 -194
- package/dialects/mysql/BaseMySqlPlatform.d.ts +64 -45
- package/dialects/mysql/BaseMySqlPlatform.js +134 -131
- package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
- package/dialects/mysql/MySqlExceptionConverter.js +91 -77
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
- package/dialects/mysql/MySqlNativeQueryBuilder.js +66 -69
- package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -39
- package/dialects/mysql/MySqlSchemaHelper.js +327 -319
- package/dialects/oracledb/OracleDialect.d.ts +81 -52
- package/dialects/oracledb/OracleDialect.js +155 -149
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
- package/dialects/oracledb/OracleNativeQueryBuilder.js +232 -236
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +109 -105
- package/dialects/postgresql/BasePostgreSqlPlatform.js +354 -350
- package/dialects/postgresql/FullTextType.d.ts +10 -6
- package/dialects/postgresql/FullTextType.js +51 -51
- package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
- package/dialects/postgresql/PostgreSqlExceptionConverter.js +55 -43
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
- package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +102 -82
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +733 -705
- package/dialects/sqlite/BaseSqliteConnection.d.ts +3 -5
- package/dialects/sqlite/BaseSqliteConnection.js +21 -19
- package/dialects/sqlite/NodeSqliteDialect.d.ts +1 -1
- package/dialects/sqlite/NodeSqliteDialect.js +23 -23
- package/dialects/sqlite/SqliteDriver.d.ts +1 -1
- package/dialects/sqlite/SqliteDriver.js +3 -3
- package/dialects/sqlite/SqliteExceptionConverter.d.ts +6 -6
- package/dialects/sqlite/SqliteExceptionConverter.js +67 -51
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
- package/dialects/sqlite/SqlitePlatform.d.ts +63 -72
- package/dialects/sqlite/SqlitePlatform.js +139 -139
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +70 -60
- package/dialects/sqlite/SqliteSchemaHelper.js +533 -520
- package/package.json +3 -3
- package/plugin/index.d.ts +42 -35
- package/plugin/index.js +43 -36
- package/plugin/transformer.d.ts +117 -94
- package/plugin/transformer.js +890 -881
- package/query/ArrayCriteriaNode.d.ts +4 -4
- package/query/ArrayCriteriaNode.js +18 -18
- package/query/CriteriaNode.d.ts +35 -25
- package/query/CriteriaNode.js +133 -123
- package/query/CriteriaNodeFactory.d.ts +49 -6
- package/query/CriteriaNodeFactory.js +97 -94
- package/query/NativeQueryBuilder.d.ts +118 -118
- package/query/NativeQueryBuilder.js +484 -480
- package/query/ObjectCriteriaNode.d.ts +12 -12
- package/query/ObjectCriteriaNode.js +298 -282
- package/query/QueryBuilder.d.ts +1557 -905
- package/query/QueryBuilder.js +2322 -2192
- package/query/QueryBuilderHelper.d.ts +153 -72
- package/query/QueryBuilderHelper.js +1079 -1028
- package/query/ScalarCriteriaNode.d.ts +3 -3
- package/query/ScalarCriteriaNode.js +53 -46
- package/query/enums.d.ts +14 -14
- package/query/enums.js +14 -14
- package/query/raw.d.ts +16 -6
- package/query/raw.js +10 -10
- package/schema/DatabaseSchema.d.ts +73 -50
- package/schema/DatabaseSchema.js +331 -307
- package/schema/DatabaseTable.d.ts +96 -73
- package/schema/DatabaseTable.js +1012 -927
- package/schema/SchemaComparator.d.ts +70 -66
- package/schema/SchemaComparator.js +766 -740
- package/schema/SchemaHelper.d.ts +109 -95
- package/schema/SchemaHelper.js +675 -659
- package/schema/SqlSchemaGenerator.d.ts +78 -58
- package/schema/SqlSchemaGenerator.js +535 -501
- package/typings.d.ts +380 -266
|
@@ -3,247 +3,243 @@ import { QueryType } from '../../query/enums.js';
|
|
|
3
3
|
import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
|
|
4
4
|
/** @internal */
|
|
5
5
|
export function markOutBindings(obj) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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');
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
};
|
|
148
|
+
}
|
|
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)} = ?`;
|
|
123
205
|
});
|
|
124
|
-
this.
|
|
125
|
-
|
|
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
|
-
}
|
|
206
|
+
this.parts.push(parts.join(', '));
|
|
207
|
+
}
|
|
208
|
+
/* v8 ignore stop */
|
|
214
209
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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);
|
|
239
|
+
}
|
|
240
|
+
if (this.options.limit != null) {
|
|
241
|
+
this.parts.push(`fetch next ? rows only`);
|
|
242
|
+
this.params.push(this.options.limit);
|
|
248
243
|
}
|
|
244
|
+
}
|
|
249
245
|
}
|