@mikro-orm/knex 5.7.15-dev.36 → 5.7.15-dev.38

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.
@@ -335,7 +335,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
335
335
  const uniqueFields = core_1.Utils.isPlainObject(where) ? Object.keys(where) : meta.primaryKeys;
336
336
  /* istanbul ignore next */
337
337
  qb.insert(data)
338
- .onConflict(uniqueFields.map(p => meta?.properties[p]?.fieldNames[0] ?? p))
338
+ .onConflict(uniqueFields)
339
339
  .merge(Object.keys(data).filter(f => !uniqueFields.includes(f)))
340
340
  .returning(meta?.comparableProps.filter(p => !p.lazy && !p.embeddable && !(p.name in data)).map(p => p.name) ?? '*');
341
341
  }
@@ -357,7 +357,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
357
357
  const uniqueFields = core_1.Utils.isPlainObject(where[0]) ? Object.keys(where[0]) : meta.primaryKeys;
358
358
  const qb = this.createQueryBuilder(entityName, options.ctx, 'write', options.convertCustomTypes).withSchema(this.getSchemaName(meta, options));
359
359
  qb.insert(data)
360
- .onConflict(uniqueFields.map(p => meta.properties[p]?.fieldNames[0] ?? p))
360
+ .onConflict(uniqueFields)
361
361
  .merge(Object.keys(data[0]).filter(f => !uniqueFields.includes(f)))
362
362
  .returning(meta.comparableProps.filter(p => !p.lazy && !p.embeddable && !(p.name in data[0])).map(p => p.name) ?? '*');
363
363
  return qb.execute('run', false);
@@ -684,9 +684,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
684
684
  if (!deleteDiff) {
685
685
  deleteDiff = [];
686
686
  }
687
+ const pivotMeta = this.metadata.find(prop.pivotEntity);
687
688
  if (deleteDiff === true || deleteDiff.length > 0) {
688
689
  const qb1 = this.createQueryBuilder(prop.pivotEntity, options?.ctx, 'write')
689
- .withSchema(this.getSchemaName(meta, options))
690
+ .withSchema(this.getSchemaName(pivotMeta, options))
690
691
  .unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES);
691
692
  const knex = qb1.getKnex();
692
693
  if (Array.isArray(deleteDiff)) {
@@ -712,7 +713,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
712
713
  await core_1.Utils.runSerial(items, item => {
713
714
  return this.createQueryBuilder(prop.pivotEntity, options?.ctx, 'write')
714
715
  .unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES)
715
- .withSchema(this.getSchemaName(meta, options))
716
+ .withSchema(this.getSchemaName(pivotMeta, options))
716
717
  .insert(item)
717
718
  .execute('run', false);
718
719
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.7.15-dev.36",
3
+ "version": "5.7.15-dev.38",
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.7.14"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "~5.7.15-dev.36",
70
- "@mikro-orm/entity-generator": "~5.7.15-dev.36",
71
- "@mikro-orm/migrations": "~5.7.15-dev.36",
69
+ "@mikro-orm/core": "~5.7.15-dev.38",
70
+ "@mikro-orm/entity-generator": "~5.7.15-dev.38",
71
+ "@mikro-orm/migrations": "~5.7.15-dev.38",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",
@@ -34,7 +34,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
34
34
  private readonly context?;
35
35
  private connectionType?;
36
36
  private readonly em?;
37
- get mainAlias(): Alias;
37
+ get mainAlias(): Alias<T>;
38
38
  get alias(): string;
39
39
  get helper(): QueryBuilderHelper;
40
40
  /** @internal */
@@ -244,9 +244,16 @@ class QueryBuilder {
244
244
  return this;
245
245
  }
246
246
  onConflict(fields = []) {
247
+ const meta = this.mainAlias.metadata;
247
248
  this.ensureNotFinalized();
248
- this._onConflict = this._onConflict || [];
249
- this._onConflict.push({ fields: core_1.Utils.asArray(fields).map(f => f.toString()) });
249
+ this._onConflict ?? (this._onConflict = []);
250
+ this._onConflict.push({
251
+ fields: core_1.Utils.asArray(fields).flatMap(f => {
252
+ const key = f.toString();
253
+ /* istanbul ignore next */
254
+ return meta.properties[key]?.fieldNames ?? [key];
255
+ }),
256
+ });
250
257
  return this;
251
258
  }
252
259
  ignore() {
@@ -16,7 +16,7 @@ export declare class QueryBuilderHelper {
16
16
  private readonly driver;
17
17
  private readonly platform;
18
18
  private readonly metadata;
19
- constructor(entityName: string, alias: string, aliasMap: Dictionary<Alias>, subQueries: Dictionary<string>, knex: Knex, driver: AbstractSqlDriver);
19
+ constructor(entityName: string, alias: string, aliasMap: Dictionary<Alias<any>>, subQueries: Dictionary<string>, knex: Knex, driver: AbstractSqlDriver);
20
20
  mapper(field: string | Knex.Raw, type?: QueryType): string;
21
21
  mapper(field: string | Knex.Raw, type?: QueryType, value?: any, alias?: string | null): string;
22
22
  processData(data: Dictionary, convertCustomTypes: boolean, multi?: boolean): any;
@@ -61,9 +61,9 @@ export declare class QueryBuilderHelper {
61
61
  isTableNameAliasRequired(type?: QueryType): boolean;
62
62
  private mapData;
63
63
  }
64
- export interface Alias {
64
+ export interface Alias<T> {
65
65
  aliasName: string;
66
66
  entityName: string;
67
- metadata?: EntityMetadata;
67
+ metadata?: EntityMetadata<T>;
68
68
  subQuery?: Knex.QueryBuilder;
69
69
  }