@mikro-orm/knex 7.0.0-dev.14 → 7.0.0-dev.15

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.
@@ -82,7 +82,7 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
82
82
  }
83
83
  this.parts.push('then update set');
84
84
  if (!clause.merge || Array.isArray(clause.merge)) {
85
- const parts = keys
85
+ const parts = (clause.merge || keys)
86
86
  .filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
87
87
  .map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
88
88
  this.parts.push(parts.join(', '));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "7.0.0-dev.14",
3
+ "version": "7.0.0-dev.15",
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
  "type": "module",
6
6
  "exports": {
@@ -54,9 +54,9 @@
54
54
  "sqlstring": "2.3.3"
55
55
  },
56
56
  "devDependencies": {
57
- "@mikro-orm/core": "^6.4.13"
57
+ "@mikro-orm/core": "^6.4.14"
58
58
  },
59
59
  "peerDependencies": {
60
- "@mikro-orm/core": "7.0.0-dev.14"
60
+ "@mikro-orm/core": "7.0.0-dev.15"
61
61
  }
62
62
  }
@@ -684,7 +684,7 @@ export class QueryBuilder {
684
684
  }
685
685
  const query = this.toQuery();
686
686
  const cached = await this.em?.tryCache(this.mainAlias.entityName, this._cache, ['qb.execute', query.sql, query.params, method]);
687
- if (cached?.data) {
687
+ if (cached?.data !== undefined) {
688
688
  return cached.data;
689
689
  }
690
690
  const write = method === 'run' || !this.platform.getConfig().get('preferReadReplicas');
@@ -251,6 +251,105 @@ export class QueryBuilderHelper {
251
251
  }
252
252
  return { sql, params };
253
253
  }
254
+ // <<<<<<< HEAD
255
+ // private processJoinClause(key: string, value: unknown, alias: string, params: Knex.Value[], operator = '$eq'): string {
256
+ // if (Utils.isGroupOperator(key) && Array.isArray(value)) {
257
+ // const parts = value.map(sub => {
258
+ // return this.wrapQueryGroup(Object.keys(sub).map(k => this.processJoinClause(k, sub[k], alias, params)));
259
+ // });
260
+ // return this.wrapQueryGroup(parts, key);
261
+ // }
262
+ //
263
+ // const rawField = RawQueryFragment.getKnownFragment(key);
264
+ //
265
+ // if (!rawField && !Utils.isOperator(key, false) && !this.isPrefixed(key)) {
266
+ // key = `${alias}.${key}`;
267
+ // }
268
+ //
269
+ // if (this.isSimpleRegExp(value)) {
270
+ // params.push(this.getRegExpParam(value));
271
+ // return `${this.knex.ref(this.mapper(key))} like ?`;
272
+ // }
273
+ //
274
+ // if (value instanceof RegExp) {
275
+ // value = this.platform.getRegExpValue(value);
276
+ // }
277
+ //
278
+ // if (Utils.isOperator(key, false) && Utils.isPlainObject(value)) {
279
+ // const parts = Object.keys(value).map(k => this.processJoinClause(k, (value as Dictionary)[k], alias, params, key));
280
+ //
281
+ // return key === '$not' ? `not ${this.wrapQueryGroup(parts)}` : this.wrapQueryGroup(parts);
282
+ // }
283
+ //
284
+ // if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k, false))) {
285
+ // const parts = Object.keys(value).map(op => this.processJoinClause(key, (value as Dictionary)[op], alias, params, op));
286
+ //
287
+ // return this.wrapQueryGroup(parts);
288
+ // }
289
+ //
290
+ // const [fromAlias, fromField] = this.splitField(key as EntityKey);
291
+ // const prop = this.getProperty(fromField, fromAlias);
292
+ // operator = operator === '$not' ? '$eq' : operator;
293
+ // const column = this.mapper(key, undefined, undefined, null);
294
+ //
295
+ // if (value === null) {
296
+ // return `${this.knex.ref(column)} is ${operator === '$ne' ? 'not ' : ''}null`;
297
+ // }
298
+ //
299
+ // if (operator === '$fulltext' && prop) {
300
+ // const query = this.knex.raw(this.platform.getFullTextWhereClause(prop), {
301
+ // column,
302
+ // query: this.knex.raw('?'),
303
+ // }).toSQL().toNative();
304
+ // params.push(value as Knex.Value);
305
+ //
306
+ // return query.sql;
307
+ // }
308
+ //
309
+ // const replacement = this.getOperatorReplacement(operator, { [operator]: value });
310
+ //
311
+ // if (['$in', '$nin'].includes(operator) && Array.isArray(value)) {
312
+ // params.push(...value as Knex.Value[]);
313
+ // return `${this.knex.ref(column)} ${replacement} (${value.map(() => '?').join(', ')})`;
314
+ // }
315
+ //
316
+ // if (operator === '$exists') {
317
+ // value = null;
318
+ // }
319
+ //
320
+ // if (rawField) {
321
+ // let sql = rawField.sql.replaceAll(ALIAS_REPLACEMENT, alias);
322
+ // params.push(...rawField.params as Knex.Value[]);
323
+ // params.push(...Utils.asArray(value) as Knex.Value[]);
324
+ //
325
+ // if ((Utils.asArray(value) as Knex.Value[]).length > 0) {
326
+ // sql += ' = ?';
327
+ // }
328
+ //
329
+ // return sql;
330
+ // }
331
+ //
332
+ // if (value !== null) {
333
+ // if (prop?.customType) {
334
+ // value = prop.customType.convertToDatabaseValue(value, this.platform, { fromQuery: true, key, mode: 'query' });
335
+ // }
336
+ //
337
+ // params.push(value as Knex.Value);
338
+ // }
339
+ //
340
+ // return `${this.knex.ref(column)} ${replacement} ${value === null ? 'null' : '?'}`;
341
+ // }
342
+ //
343
+ // private wrapQueryGroup(parts: string[], operator = '$and') {
344
+ // if (parts.length === 1) {
345
+ // return parts[0];
346
+ // }
347
+ //
348
+ // return `(${parts.join(` ${GroupOperator[operator as keyof typeof GroupOperator]} `)})`;
349
+ // }
350
+ //
351
+ // mapJoinColumns(type: QueryType, join: JoinOptions): (string | Knex.Raw)[] {
352
+ // =======
254
353
  mapJoinColumns(type, join) {
255
354
  if (join.prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(join.prop.kind)) {
256
355
  return join.prop.fieldNames.map((_fieldName, idx) => {
@@ -104,7 +104,7 @@ export class DatabaseTable {
104
104
  this.columns[field].default = defaultValue;
105
105
  });
106
106
  if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
107
- const constraintName = this.getIndexName(true, prop.fieldNames, 'foreign');
107
+ const constraintName = this.getIndexName(prop.foreignKeyName ?? true, prop.fieldNames, 'foreign');
108
108
  let schema = prop.targetMeta.root.schema === '*' ? this.schema : (prop.targetMeta.root.schema ?? config.get('schema', this.platform.getDefaultSchemaName()));
109
109
  if (prop.referencedTableName.includes('.')) {
110
110
  schema = undefined;