@mikro-orm/knex 5.9.5-dev.0 → 5.9.5-dev.2

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.
@@ -81,7 +81,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
81
81
  if (typeof meta.expression === 'string') {
82
82
  return this.wrapVirtualExpressionInSubquery(meta, meta.expression, where, options, type);
83
83
  }
84
- const em = this.createEntityManager(false);
84
+ const em = this.createEntityManager();
85
85
  em.setTransactionContext(options.ctx);
86
86
  const res = meta.expression(em, where, options);
87
87
  if (typeof res === 'string') {
@@ -374,6 +374,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
374
374
  }
375
375
  const collections = options.processCollections ? data.map(d => this.extractManyToMany(entityName, d)) : [];
376
376
  const keys = new Set();
377
+ const fields = new Set();
377
378
  data.forEach(row => Object.keys(row).forEach(k => keys.add(k)));
378
379
  const pkCond = core_1.Utils.flatten(meta.primaryKeys.map(pk => meta.properties[pk].fieldNames)).map(pk => `${this.platform.quoteIdentifier(pk)} = ?`).join(' and ');
379
380
  const params = [];
@@ -381,6 +382,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
381
382
  keys.forEach(key => {
382
383
  const prop = meta.properties[key];
383
384
  prop.fieldNames.forEach((fieldName, fieldNameIdx) => {
385
+ if (fields.has(fieldName)) {
386
+ return;
387
+ }
388
+ fields.add(fieldName);
384
389
  sql += `${this.platform.quoteIdentifier(fieldName)} = case`;
385
390
  where.forEach((cond, idx) => {
386
391
  if (key in data[idx]) {
@@ -14,7 +14,7 @@ export declare abstract class AbstractSqlPlatform extends Platform {
14
14
  quoteValue(value: any): string;
15
15
  formatQuery(sql: string, params: readonly any[]): string;
16
16
  getSearchJsonPropertySQL(path: string, type: string, aliased: boolean): string;
17
- getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean): string;
17
+ getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string;
18
18
  isRaw(value: any): boolean;
19
19
  supportsSchemas(): boolean;
20
20
  /** @inheritDoc */
@@ -82,7 +82,7 @@ class AbstractSqlPlatform extends core_1.Platform {
82
82
  getSearchJsonPropertySQL(path, type, aliased) {
83
83
  return this.getSearchJsonPropertyKey(path.split('->'), type, aliased);
84
84
  }
85
- getSearchJsonPropertyKey(path, type, aliased) {
85
+ getSearchJsonPropertyKey(path, type, aliased, value) {
86
86
  const [a, ...b] = path;
87
87
  const quoteKey = (key) => key.match(/^[a-z]\w*$/i) ? key : `"${key}"`;
88
88
  if (aliased) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.9.5-dev.0",
3
+ "version": "5.9.5-dev.2",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,9 +66,9 @@
66
66
  "@mikro-orm/core": "^5.9.4"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "5.9.5-dev.0",
70
- "@mikro-orm/entity-generator": "5.9.5-dev.0",
71
- "@mikro-orm/migrations": "5.9.5-dev.0",
69
+ "@mikro-orm/core": "5.9.5-dev.2",
70
+ "@mikro-orm/entity-generator": "5.9.5-dev.2",
71
+ "@mikro-orm/migrations": "5.9.5-dev.2",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",
@@ -20,6 +20,12 @@ class ScalarCriteriaNode extends CriteriaNode_1.CriteriaNode {
20
20
  qb.addSelect(field);
21
21
  }
22
22
  }
23
+ if (this.payload && typeof this.payload === 'object') {
24
+ const keys = Object.keys(this.payload).filter(key => core_1.Utils.isArrayOperator(key) && Array.isArray(this.payload[key]));
25
+ for (const key of keys) {
26
+ this.payload[key] = JSON.stringify(this.payload[key]);
27
+ }
28
+ }
23
29
  return this.payload;
24
30
  }
25
31
  willAutoJoin(qb, alias) {
@@ -1,3 +1,4 @@
1
+ import { type Dictionary } from '@mikro-orm/core';
1
2
  import type { Check, Column, ForeignKey, Index, SchemaDifference, TableDifference } from '../typings';
2
3
  import type { DatabaseSchema } from './DatabaseSchema';
3
4
  import type { DatabaseTable } from './DatabaseTable';
@@ -51,6 +52,7 @@ export declare class SchemaComparator {
51
52
  */
52
53
  isIndexFulfilledBy(index1: Index, index2: Index): boolean;
53
54
  diffCheck(check1: Check, check2: Check): boolean;
55
+ parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
54
56
  hasSameDefaultValue(from: Column, to: Column): boolean;
55
57
  private mapColumnToProperty;
56
58
  private log;
@@ -436,6 +436,15 @@ class SchemaComparator {
436
436
  const simplify = (str) => str?.replace(/['"`()]/g, '').toLowerCase();
437
437
  return simplify(check1.expression) !== simplify(check2.expression);
438
438
  }
439
+ parseJsonDefault(defaultValue) {
440
+ if (!defaultValue) {
441
+ return null;
442
+ }
443
+ const val = defaultValue
444
+ .replace(/^(_\w+\\)?'(.*?)\\?'$/, '$2')
445
+ .replace(/^\(?'(.*?)'\)?$/, '$1');
446
+ return (0, core_1.parseJsonSafe)(val);
447
+ }
439
448
  hasSameDefaultValue(from, to) {
440
449
  if (from.default == null || from.default.toString().toLowerCase() === 'null' || from.default.toString().startsWith('nextval(')) {
441
450
  return to.default == null || to.default.toLowerCase() === 'null';
@@ -446,8 +455,8 @@ class SchemaComparator {
446
455
  return defaultValueFrom === defaultValueTo;
447
456
  }
448
457
  if (to.mappedType instanceof core_1.JsonType) {
449
- const defaultValueFrom = (0, core_1.parseJsonSafe)(from.default.replace(/^(_\w+\\)?'(.*?)\\?'$/, '$2'));
450
- const defaultValueTo = (0, core_1.parseJsonSafe)(to.default?.replace(/^\(?'(.*?)'\)?$/, '$1'));
458
+ const defaultValueFrom = this.parseJsonDefault(from.default);
459
+ const defaultValueTo = this.parseJsonDefault(to.default);
451
460
  return core_1.Utils.equals(defaultValueFrom, defaultValueTo);
452
461
  }
453
462
  if (to.mappedType instanceof core_1.DateTimeType && from.default && to.default) {