@mikro-orm/sql 7.3.0-dev.20 → 7.3.0-dev.21
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/dialects/mssql/MsSqlNativeQueryBuilder.js +4 -3
- package/dialects/mysql/BaseMySqlPlatform.d.ts +8 -0
- package/dialects/mysql/BaseMySqlPlatform.js +13 -1
- package/dialects/mysql/MySqlNativeQueryBuilder.js +4 -3
- package/dialects/mysql/MySqlSchemaHelper.js +2 -4
- package/dialects/oracledb/OracleNativeQueryBuilder.js +4 -3
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +3 -3
- package/query/NativeQueryBuilder.d.ts +6 -0
- package/query/NativeQueryBuilder.js +22 -3
- package/query/QueryBuilder.d.ts +5 -0
- package/query/QueryBuilder.js +32 -4
- package/query/QueryBuilderHelper.js +17 -3
- package/schema/DatabaseTable.js +2 -0
- package/schema/SchemaComparator.d.ts +1 -0
- package/schema/SchemaComparator.js +13 -1
|
@@ -130,17 +130,18 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
|
|
|
130
130
|
}
|
|
131
131
|
this.parts.push('then update set');
|
|
132
132
|
if (!clause.merge || Array.isArray(clause.merge)) {
|
|
133
|
-
const
|
|
133
|
+
const merge = clause.merge?.length ? clause.merge : keys;
|
|
134
|
+
const parts = merge
|
|
134
135
|
.filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
|
|
135
136
|
.map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
|
|
136
|
-
this.parts.push(
|
|
137
|
+
this.parts.push(this.joinVersionMerge(clause, parts, merge));
|
|
137
138
|
}
|
|
138
139
|
else if (typeof clause.merge === 'object') {
|
|
139
140
|
const parts = Object.entries(clause.merge).map(([key, value]) => {
|
|
140
141
|
this.params.push(value);
|
|
141
142
|
return `${this.getTableName()}.${this.quote(key)} = ?`;
|
|
142
143
|
});
|
|
143
|
-
this.parts.push(
|
|
144
|
+
this.parts.push(this.joinVersionMerge(clause, parts, Object.keys(clause.merge)));
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
this.addOutputClause('inserted');
|
|
@@ -18,6 +18,14 @@ export declare class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
18
18
|
sortsNullsLowest(): boolean;
|
|
19
19
|
/** mysql reads backslashes in string literals as escapes, so defaults need the same escaping as values (minus the needless `\"`). */
|
|
20
20
|
quoteDefaultValue(value: string): string;
|
|
21
|
+
/** enum items are escaped the way mysql prints them back in `column_type`, so the next schema diff matches. */
|
|
22
|
+
getEnumTypeDeclarationSQL(column: {
|
|
23
|
+
items?: unknown[];
|
|
24
|
+
fieldNames: string[];
|
|
25
|
+
length?: number;
|
|
26
|
+
unsigned?: boolean;
|
|
27
|
+
autoincrement?: boolean;
|
|
28
|
+
}): string;
|
|
21
29
|
supportsMultiColumnCountDistinct(): boolean;
|
|
22
30
|
/** @internal */
|
|
23
31
|
createNativeQueryBuilder(): MySqlNativeQueryBuilder;
|
|
@@ -12,6 +12,13 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
12
12
|
bigint: 'bigint',
|
|
13
13
|
boolean: 'unsigned',
|
|
14
14
|
};
|
|
15
|
+
#enumItemEscapes = {
|
|
16
|
+
'\0': '\\0',
|
|
17
|
+
'\n': '\\n',
|
|
18
|
+
'\r': '\\r',
|
|
19
|
+
"'": "''",
|
|
20
|
+
'\\': '\\\\',
|
|
21
|
+
};
|
|
15
22
|
ORDER_BY_NULLS_TRANSLATE = {
|
|
16
23
|
[QueryOrder.asc_nulls_first]: 'is not null',
|
|
17
24
|
[QueryOrder.asc_nulls_last]: 'is null',
|
|
@@ -26,6 +33,11 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
26
33
|
quoteDefaultValue(value) {
|
|
27
34
|
return this.quoteValue(value).replaceAll('\\"', '"');
|
|
28
35
|
}
|
|
36
|
+
/** enum items are escaped the way mysql prints them back in `column_type`, so the next schema diff matches. */
|
|
37
|
+
getEnumTypeDeclarationSQL(column) {
|
|
38
|
+
const items = column.items?.map(item => typeof item === 'string' ? item.replace(/[\0\n\r'\\]/g, c => this.#enumItemEscapes[c]) : item);
|
|
39
|
+
return super.getEnumTypeDeclarationSQL({ ...column, items });
|
|
40
|
+
}
|
|
29
41
|
supportsMultiColumnCountDistinct() {
|
|
30
42
|
return true;
|
|
31
43
|
}
|
|
@@ -34,7 +46,7 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
34
46
|
return new MySqlNativeQueryBuilder(this);
|
|
35
47
|
}
|
|
36
48
|
formatIndexHint(indexNames) {
|
|
37
|
-
return `use index(${indexNames.join(', ')})`;
|
|
49
|
+
return `use index(${indexNames.map(name => this.quoteIdentifier(name)).join(', ')})`;
|
|
38
50
|
}
|
|
39
51
|
getDefaultCharset() {
|
|
40
52
|
return 'utf8mb4';
|
|
@@ -58,16 +58,17 @@ export class MySqlNativeQueryBuilder extends NativeQueryBuilder {
|
|
|
58
58
|
this.params.push(clause.merge[field]);
|
|
59
59
|
return `${this.quote(field)} = ?`;
|
|
60
60
|
});
|
|
61
|
-
this.parts.push(
|
|
61
|
+
this.parts.push(this.joinVersionMerge(clause, fields, Object.keys(clause.merge)));
|
|
62
62
|
}
|
|
63
63
|
else if (clause.merge.length === 0) {
|
|
64
64
|
const dataAsArray = Utils.asArray(this.options.data);
|
|
65
65
|
const keys = Object.keys(dataAsArray[0]);
|
|
66
|
-
|
|
66
|
+
const fields = keys.map(key => `${this.quote(key)} = values(${this.quote(key)})`);
|
|
67
|
+
this.parts.push(this.joinVersionMerge(clause, fields, keys));
|
|
67
68
|
}
|
|
68
69
|
else {
|
|
69
70
|
const fields = clause.merge.map(key => `${this.quote(key)} = values(${this.quote(key)})`);
|
|
70
|
-
this.parts.push(
|
|
71
|
+
this.parts.push(this.joinVersionMerge(clause, fields, clause.merge));
|
|
71
72
|
}
|
|
72
73
|
if (clause.where) {
|
|
73
74
|
this.parts.push(`where ${clause.where.sql}`);
|
|
@@ -590,10 +590,8 @@ export class MySqlSchemaHelper extends SchemaHelper {
|
|
|
590
590
|
const enums = await connection.execute(sql, [], 'all', ctx);
|
|
591
591
|
return enums.reduce((o, item) => {
|
|
592
592
|
o[item.table_name] ??= {};
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
.split(',')
|
|
596
|
-
.map((item) => /'(.*)'/.exec(item)[1]);
|
|
593
|
+
// items can hold commas, doubled quotes and backslash escapes
|
|
594
|
+
o[item.table_name][item.column_name] = [...item.column_type.matchAll(/'((?:''|\\.|[^'\\])*)'/g)].map(([, value]) => this.unescapeDefault(value.replaceAll("''", "'")));
|
|
597
595
|
return o;
|
|
598
596
|
}, {});
|
|
599
597
|
}
|
|
@@ -181,7 +181,8 @@ export class OracleNativeQueryBuilder extends NativeQueryBuilder {
|
|
|
181
181
|
if (!clause.ignore) {
|
|
182
182
|
/* v8 ignore next: merge type branch */
|
|
183
183
|
if (!clause.merge || Array.isArray(clause.merge)) {
|
|
184
|
-
const
|
|
184
|
+
const merge = clause.merge?.length ? clause.merge : keys;
|
|
185
|
+
const mergeParts = merge
|
|
185
186
|
.filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
|
|
186
187
|
.filter((field) => keys.includes(field)) // only reference columns present in the source data
|
|
187
188
|
.map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
|
|
@@ -193,7 +194,7 @@ export class OracleNativeQueryBuilder extends NativeQueryBuilder {
|
|
|
193
194
|
this.params.push(...clause.where.params);
|
|
194
195
|
}
|
|
195
196
|
this.parts.push('then update set');
|
|
196
|
-
this.parts.push(
|
|
197
|
+
this.parts.push(this.joinVersionMerge(clause, mergeParts, merge));
|
|
197
198
|
}
|
|
198
199
|
} /* v8 ignore start: object-form merge branch */
|
|
199
200
|
else if (typeof clause.merge === 'object') {
|
|
@@ -207,7 +208,7 @@ export class OracleNativeQueryBuilder extends NativeQueryBuilder {
|
|
|
207
208
|
this.params.push(value);
|
|
208
209
|
return `${this.getTableName()}.${this.quote(key)} = ?`;
|
|
209
210
|
});
|
|
210
|
-
this.parts.push(
|
|
211
|
+
this.parts.push(this.joinVersionMerge(clause, parts, Object.keys(clause.merge)));
|
|
211
212
|
}
|
|
212
213
|
/* v8 ignore stop */
|
|
213
214
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.3.0-dev.
|
|
3
|
+
"version": "7.3.0-dev.21",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"kysely": "0.29.8"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mikro-orm/core": "^7.2.
|
|
53
|
+
"@mikro-orm/core": "^7.2.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.3.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.3.0-dev.21"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -66,9 +66,14 @@ interface OnConflictClause {
|
|
|
66
66
|
sql: string;
|
|
67
67
|
params: unknown[];
|
|
68
68
|
};
|
|
69
|
+
version?: {
|
|
70
|
+
field: string;
|
|
71
|
+
timestamp?: string;
|
|
72
|
+
};
|
|
69
73
|
}
|
|
70
74
|
/** @internal */
|
|
71
75
|
export declare class NativeQueryBuilder implements Subquery {
|
|
76
|
+
#private;
|
|
72
77
|
protected readonly platform: AbstractSqlPlatform;
|
|
73
78
|
readonly __subquery: true;
|
|
74
79
|
protected type?: QueryType;
|
|
@@ -103,6 +108,7 @@ export declare class NativeQueryBuilder implements Subquery {
|
|
|
103
108
|
};
|
|
104
109
|
protected addLockClause(): void;
|
|
105
110
|
protected addOnConflictClause(): void;
|
|
111
|
+
protected joinVersionMerge(clause: OnConflictClause, parts: string[], merged: unknown[]): string;
|
|
106
112
|
protected combineParts(): {
|
|
107
113
|
sql: string;
|
|
108
114
|
params: unknown[];
|
|
@@ -7,6 +7,8 @@ export class NativeQueryBuilder {
|
|
|
7
7
|
parts = [];
|
|
8
8
|
params = [];
|
|
9
9
|
options = {};
|
|
10
|
+
/** the table name or alias usable as a column qualifier (without the alias definition or index hint) */
|
|
11
|
+
#tableQualifier;
|
|
10
12
|
constructor(platform) {
|
|
11
13
|
this.platform = platform;
|
|
12
14
|
}
|
|
@@ -33,8 +35,14 @@ export class NativeQueryBuilder {
|
|
|
33
35
|
const asKeyword = this.platform.usesAsKeyword() ? ' as ' : ' ';
|
|
34
36
|
const alias = options?.alias ? `${asKeyword}${this.platform.quoteIdentifier(options.alias)}` : '';
|
|
35
37
|
const schema = options?.schema && options.schema !== this.platform.getDefaultSchemaName() ? `${options.schema}.` : '';
|
|
38
|
+
this.#tableQualifier = options?.alias
|
|
39
|
+
? this.platform.quoteIdentifier(options.alias)
|
|
40
|
+
: this.quote(schema + tableName);
|
|
36
41
|
tableName = this.quote(schema + tableName) + alias;
|
|
37
42
|
}
|
|
43
|
+
else {
|
|
44
|
+
this.#tableQualifier = undefined;
|
|
45
|
+
}
|
|
38
46
|
this.options.tableName = tableName;
|
|
39
47
|
this.options.indexHint = options?.indexHint;
|
|
40
48
|
return this;
|
|
@@ -174,19 +182,19 @@ export class NativeQueryBuilder {
|
|
|
174
182
|
this.params.push(clause.merge[field]);
|
|
175
183
|
return `${this.quote(field)} = ?`;
|
|
176
184
|
});
|
|
177
|
-
this.parts.push(
|
|
185
|
+
this.parts.push(this.joinVersionMerge(clause, fields, Object.keys(clause.merge)));
|
|
178
186
|
}
|
|
179
187
|
else if (clause.merge) {
|
|
180
188
|
this.parts.push('do update set');
|
|
181
189
|
if (clause.merge.length) {
|
|
182
190
|
const fields = clause.merge.map(field => `${this.quote(field)} = excluded.${this.quote(field)}`);
|
|
183
|
-
this.parts.push(
|
|
191
|
+
this.parts.push(this.joinVersionMerge(clause, fields, clause.merge));
|
|
184
192
|
}
|
|
185
193
|
else {
|
|
186
194
|
const dataAsArray = Utils.asArray(this.options.data);
|
|
187
195
|
const keys = Object.keys(dataAsArray[0]);
|
|
188
196
|
const fields = keys.map(field => `${this.quote(field)} = excluded.${this.quote(field)}`);
|
|
189
|
-
this.parts.push(
|
|
197
|
+
this.parts.push(this.joinVersionMerge(clause, fields, keys));
|
|
190
198
|
}
|
|
191
199
|
}
|
|
192
200
|
if (clause.where) {
|
|
@@ -194,6 +202,17 @@ export class NativeQueryBuilder {
|
|
|
194
202
|
this.params.push(...clause.where.params);
|
|
195
203
|
}
|
|
196
204
|
}
|
|
205
|
+
joinVersionMerge(clause, parts, merged) {
|
|
206
|
+
if (clause.version && !merged.includes(clause.version.field)) {
|
|
207
|
+
const field = this.quote(clause.version.field);
|
|
208
|
+
// the existing row's version, as the `version + 1` of an update (a bare column is ambiguous with `excluded`)
|
|
209
|
+
parts = [
|
|
210
|
+
...parts,
|
|
211
|
+
`${field} = ${clause.version.timestamp ?? `${this.#tableQualifier ?? this.getTableName()}.${field} + 1`}`,
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
return parts.join(', ');
|
|
215
|
+
}
|
|
197
216
|
combineParts() {
|
|
198
217
|
let sql = this.parts.join(' ');
|
|
199
218
|
if (this.options.wrap) {
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -803,6 +803,11 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
803
803
|
* Use `method` to specify what kind of result you want to get (array/single/meta).
|
|
804
804
|
*/
|
|
805
805
|
execute<U = any>(method?: 'all' | 'get' | 'run', options?: ExecuteOptions | boolean): Promise<U>;
|
|
806
|
+
/**
|
|
807
|
+
* An update or delete with auto-joined conditions stays a select until `finalize()` wraps it,
|
|
808
|
+
* so read the same flags `wrapModifySubQuery()` uses.
|
|
809
|
+
*/
|
|
810
|
+
private getExecuteType;
|
|
806
811
|
private getConnection;
|
|
807
812
|
/**
|
|
808
813
|
* Executes the query and returns an async iterable (async generator) that yields results one by one.
|
package/query/QueryBuilder.js
CHANGED
|
@@ -593,6 +593,16 @@ export class QueryBuilder {
|
|
|
593
593
|
o[raw('??', [key])] = o[key];
|
|
594
594
|
delete o[key];
|
|
595
595
|
}
|
|
596
|
+
// an alias-prefixed composite FK needs all its columns, like the unprefixed form gets in `renameFieldToPK()`
|
|
597
|
+
const [alias, field] = key.includes('.') ? this.helper.splitField(key, true) : [];
|
|
598
|
+
const prop = field && !Utils.isPlainObject(o[key]) ? this.helper.getProperty(field, alias) : undefined;
|
|
599
|
+
if (prop &&
|
|
600
|
+
prop.joinColumns?.length > 1 &&
|
|
601
|
+
(prop.kind === ReferenceKind.MANY_TO_ONE || (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner))) {
|
|
602
|
+
const columns = prop.polymorphic ? prop.fieldNames : prop.joinColumns;
|
|
603
|
+
o[Utils.getPrimaryKeyHash(columns.map(col => `${alias}.${col}`))] = o[key];
|
|
604
|
+
delete o[key];
|
|
605
|
+
}
|
|
596
606
|
}
|
|
597
607
|
this.helper.validateQueryOrder(o);
|
|
598
608
|
const processed = QueryHelper.processWhere({
|
|
@@ -1057,12 +1067,13 @@ export class QueryBuilder {
|
|
|
1057
1067
|
options = typeof options === 'boolean' ? { mapResults: options } : (options ?? {});
|
|
1058
1068
|
options.mergeResults ??= true;
|
|
1059
1069
|
options.mapResults ??= true;
|
|
1060
|
-
const
|
|
1070
|
+
const type = this.getExecuteType();
|
|
1071
|
+
const isRunType = [QueryType.INSERT, QueryType.UPDATE, QueryType.DELETE, QueryType.TRUNCATE].includes(type);
|
|
1061
1072
|
method ??= isRunType ? 'run' : 'all';
|
|
1062
1073
|
if (!this.connectionType && (isRunType || this.context)) {
|
|
1063
1074
|
this.connectionType = 'write';
|
|
1064
1075
|
}
|
|
1065
|
-
if (!this.#state.finalized && method === 'get' &&
|
|
1076
|
+
if (!this.#state.finalized && method === 'get' && type === QueryType.SELECT) {
|
|
1066
1077
|
this.limit(1);
|
|
1067
1078
|
}
|
|
1068
1079
|
const query = this.toQuery();
|
|
@@ -1120,6 +1131,19 @@ export class QueryBuilder {
|
|
|
1120
1131
|
await this.em?.storeCache(this.#state.cache, cached, mapped);
|
|
1121
1132
|
return mapped;
|
|
1122
1133
|
}
|
|
1134
|
+
/**
|
|
1135
|
+
* An update or delete with auto-joined conditions stays a select until `finalize()` wraps it,
|
|
1136
|
+
* so read the same flags `wrapModifySubQuery()` uses.
|
|
1137
|
+
*/
|
|
1138
|
+
getExecuteType() {
|
|
1139
|
+
if (this.#state.flags.has(QueryFlag.UPDATE_SUB_QUERY)) {
|
|
1140
|
+
return QueryType.UPDATE;
|
|
1141
|
+
}
|
|
1142
|
+
if (this.#state.flags.has(QueryFlag.DELETE_SUB_QUERY)) {
|
|
1143
|
+
return QueryType.DELETE;
|
|
1144
|
+
}
|
|
1145
|
+
return this.type;
|
|
1146
|
+
}
|
|
1123
1147
|
getConnection() {
|
|
1124
1148
|
const write = !this.platform.getConfig().get('preferReadReplicas');
|
|
1125
1149
|
const type = this.connectionType || (write ? 'write' : 'read');
|
|
@@ -2354,8 +2378,12 @@ export class QueryBuilder {
|
|
|
2354
2378
|
if (this.#state.orderBy.length > 0) {
|
|
2355
2379
|
const orderBy = [];
|
|
2356
2380
|
for (const orderMap of this.#state.orderBy) {
|
|
2357
|
-
|
|
2358
|
-
|
|
2381
|
+
// a composite FK key holds several columns, each needs its own `min()`
|
|
2382
|
+
const entries = Utils.getObjectQueryKeys(orderMap).flatMap(key => {
|
|
2383
|
+
const fields = RawQueryFragment.isKnownFragmentSymbol(key) ? [key] : Utils.splitPrimaryKeys(key);
|
|
2384
|
+
return fields.map(field => [field, orderMap[key]]);
|
|
2385
|
+
});
|
|
2386
|
+
for (const [field, direction] of entries) {
|
|
2359
2387
|
if (RawQueryFragment.isKnownFragmentSymbol(field)) {
|
|
2360
2388
|
orderBy.push({ [field]: direction });
|
|
2361
2389
|
continue;
|
|
@@ -408,6 +408,7 @@ export class QueryBuilderHelper {
|
|
|
408
408
|
return `%${value}%`;
|
|
409
409
|
}
|
|
410
410
|
appendOnConflictClause(type, onConflict, qb) {
|
|
411
|
+
const meta = this.#metadata.find(this.#entityName);
|
|
411
412
|
onConflict.forEach(item => {
|
|
412
413
|
const { fields, ignore } = item;
|
|
413
414
|
const sub = qb.onConflict({ fields, ignore });
|
|
@@ -424,6 +425,12 @@ export class QueryBuilderHelper {
|
|
|
424
425
|
mergeParam = item.merge.map(key => this.mapper(key, type));
|
|
425
426
|
}
|
|
426
427
|
sub.merge = mergeParam ?? [];
|
|
428
|
+
// a merged row is updated, so its version is bumped as `updateVersionProperty()` does
|
|
429
|
+
if (meta?.ownsVersionProperty()) {
|
|
430
|
+
const prop = meta.properties[meta.versionProperty];
|
|
431
|
+
const timestamp = prop.runtimeType === 'Date' ? this.#platform.getCurrentTimestampSQL(prop.length) : undefined;
|
|
432
|
+
sub.version = { field: prop.fieldNames[0], timestamp };
|
|
433
|
+
}
|
|
427
434
|
if (item.where) {
|
|
428
435
|
sub.where = this._appendQueryCondition(type, item.where);
|
|
429
436
|
}
|
|
@@ -557,15 +564,17 @@ export class QueryBuilderHelper {
|
|
|
557
564
|
['$in', '$nin'].includes(op) &&
|
|
558
565
|
Array.isArray(value[op]) &&
|
|
559
566
|
value[op].every((v) => Array.isArray(v));
|
|
560
|
-
|
|
567
|
+
// an empty list falls through to the generic `1 = 0` / `1 = 1` handling below
|
|
568
|
+
if (fields.length > 1 && Array.isArray(value[op]) && value[op].length > 0) {
|
|
561
569
|
const singleTuple = !value[op].every((v) => Array.isArray(v));
|
|
562
570
|
if (!this.#platform.allowsComparingTuples()) {
|
|
563
571
|
const mapped = fields.map(f => this.mapper(f, type));
|
|
564
|
-
if (op === '$in') {
|
|
572
|
+
if (op === '$in' || op === '$nin') {
|
|
565
573
|
const conds = value[op].map(() => {
|
|
566
574
|
return `(${mapped.map(field => `${this.#platform.quoteIdentifier(field)} = ?`).join(' and ')})`;
|
|
567
575
|
});
|
|
568
|
-
|
|
576
|
+
const sql = `(${conds.join(' or ')})`;
|
|
577
|
+
parts.push(op === '$in' ? sql : `not ${sql}`);
|
|
569
578
|
params.push(...Utils.flatten(value[op]));
|
|
570
579
|
return { sql: parts.join(' and '), params };
|
|
571
580
|
}
|
|
@@ -1109,6 +1118,11 @@ export class QueryBuilderHelper {
|
|
|
1109
1118
|
const meta = this.#metadata.get(this.#entityName);
|
|
1110
1119
|
const tableName = meta.tableName;
|
|
1111
1120
|
for (const key of Object.keys(cond)) {
|
|
1121
|
+
// operators are kept, only the properties inside them are qualified
|
|
1122
|
+
if (key === '$and' || key === '$or' || key === '$not') {
|
|
1123
|
+
Utils.asArray(cond[key]).forEach((sub) => this.processOnConflictCondition(sub, schema));
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1112
1126
|
const mapped = this.mapper(key, QueryType.UPSERT);
|
|
1113
1127
|
Utils.renameKey(cond, key, tableName + '.' + mapped);
|
|
1114
1128
|
}
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -1205,6 +1205,8 @@ export class DatabaseTable {
|
|
|
1205
1205
|
// collapse mysql's `""` for unset comments to `null` so both sources agree. drop entirely on
|
|
1206
1206
|
// platforms that can't read comments back (sqlite), where keeping it would flip the snapshot
|
|
1207
1207
|
comment: supportsComments ? this.comment || null : null,
|
|
1208
|
+
// JSON.stringify drops it when unset, so snapshots of unpartitioned tables stay unchanged
|
|
1209
|
+
partitioning: this.partitioning,
|
|
1208
1210
|
};
|
|
1209
1211
|
// emit RLS state only when set, so snapshots of non-RLS tables stay byte-for-byte unchanged
|
|
1210
1212
|
if (sortedPolicies.length > 0) {
|
|
@@ -92,6 +92,7 @@ export declare class SchemaComparator {
|
|
|
92
92
|
private diffPolicy;
|
|
93
93
|
parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
|
|
94
94
|
private parseDecimalDefault;
|
|
95
|
+
private parseBigIntDefault;
|
|
95
96
|
hasSameDefaultValue(from: Column, to: Column): boolean;
|
|
96
97
|
private mapColumnToProperty;
|
|
97
98
|
private log;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayType, BooleanType, DateTimeType, DecimalType, inspect, JsonType, parseJsonSafe, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { ArrayType, BigIntType, BooleanType, DateTimeType, DecimalType, inspect, JsonType, parseJsonSafe, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { DatabaseTable } from './DatabaseTable.js';
|
|
3
3
|
import { diffPartitioning } from './partitioning.js';
|
|
4
4
|
/**
|
|
@@ -1100,6 +1100,10 @@ export class SchemaComparator {
|
|
|
1100
1100
|
const value = +('' + defaultValue).replace(/^'(.+)'$/, '$1');
|
|
1101
1101
|
return Number.isFinite(value) ? value : null;
|
|
1102
1102
|
}
|
|
1103
|
+
parseBigIntDefault(defaultValue) {
|
|
1104
|
+
const value = ('' + defaultValue).replace(/^'(.+)'$/, '$1');
|
|
1105
|
+
return /^-?\d+$/.test(value) ? BigInt(value) : null;
|
|
1106
|
+
}
|
|
1103
1107
|
hasSameDefaultValue(from, to) {
|
|
1104
1108
|
if (from.default == null ||
|
|
1105
1109
|
from.default.toString().toLowerCase() === 'null' ||
|
|
@@ -1135,6 +1139,14 @@ export class SchemaComparator {
|
|
|
1135
1139
|
this.#platform.formatDecimal(defaultValueTo, to.scale));
|
|
1136
1140
|
}
|
|
1137
1141
|
}
|
|
1142
|
+
// metadata quotes bigint defaults (`'0'`) while mysql reports them bare
|
|
1143
|
+
if (to.mappedType instanceof BigIntType) {
|
|
1144
|
+
const defaultValueFrom = this.parseBigIntDefault(from.default);
|
|
1145
|
+
const defaultValueTo = this.parseBigIntDefault(to.default);
|
|
1146
|
+
if (defaultValueFrom != null && defaultValueTo != null) {
|
|
1147
|
+
return defaultValueFrom === defaultValueTo;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1138
1150
|
if (from.default && to.default) {
|
|
1139
1151
|
return from.default.toString().toLowerCase() === to.default.toString().toLowerCase();
|
|
1140
1152
|
}
|