@mikro-orm/knex 5.7.15-dev.43 → 5.7.15-dev.44

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.
@@ -1,6 +1,5 @@
1
- import type { Knex } from 'knex';
2
- import type { AnyEntity, Configuration, ConnectionOptions, EntityData, IsolationLevel, QueryResult, Transaction, TransactionEventBroadcaster } from '@mikro-orm/core';
3
- import { Connection } from '@mikro-orm/core';
1
+ import { type Knex } from 'knex';
2
+ import { Connection, type AnyEntity, type Configuration, type ConnectionOptions, type EntityData, type IsolationLevel, type QueryResult, type Transaction, type TransactionEventBroadcaster } from '@mikro-orm/core';
4
3
  import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
5
4
  export declare abstract class AbstractSqlConnection extends Connection {
6
5
  private static __patched;
@@ -1,6 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { AnyEntity, Collection, ConnectionType, Configuration, Constructor, CountOptions, DeleteOptions, Dictionary, DriverMethodOptions, EntityData, EntityDictionary, EntityField, EntityMetadata, EntityName, EntityProperty, FilterQuery, FindOneOptions, FindOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateManyOptions, NativeInsertUpdateOptions, PopulateOptions, Primary, QueryOrderMap, QueryResult, Transaction } from '@mikro-orm/core';
3
- import { DatabaseDriver, EntityManagerType } from '@mikro-orm/core';
2
+ import { DatabaseDriver, EntityManagerType, type AnyEntity, type Collection, type ConnectionType, type Configuration, type Constructor, type CountOptions, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type PopulateOptions, type Primary, type QueryOrderMap, type QueryResult, type Transaction, type UpsertOptions, type UpsertManyOptions } from '@mikro-orm/core';
4
3
  import type { AbstractSqlConnection } from './AbstractSqlConnection';
5
4
  import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
6
5
  import { QueryBuilder, QueryType } from './query';
@@ -27,8 +26,8 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
27
26
  count<T extends object>(entityName: string, where: any, options?: CountOptions<T>): Promise<number>;
28
27
  nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
29
28
  nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
30
- nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
31
- nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
29
+ nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
30
+ nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
32
31
  nativeDelete<T extends object>(entityName: string, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
33
32
  syncCollection<T extends object, O extends object>(coll: Collection<T, O>, options?: DriverMethodOptions): Promise<void>;
34
33
  loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: QueryOrderMap<T>[], ctx?: Transaction, options?: FindOptions<T, any>): Promise<Dictionary<T[]>>;
@@ -341,12 +341,18 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
341
341
  .withSchema(this.getSchemaName(meta, options));
342
342
  if (options.upsert) {
343
343
  /* istanbul ignore next */
344
- const uniqueFields = core_1.Utils.isPlainObject(where) ? Object.keys(where) : meta.primaryKeys;
345
- /* istanbul ignore next */
344
+ const uniqueFields = options.onConflictFields ?? (core_1.Utils.isPlainObject(where) ? Object.keys(where) : meta.primaryKeys);
345
+ const returning = (0, core_1.getOnConflictReturningFields)(meta, data, uniqueFields, options);
346
346
  qb.insert(data)
347
347
  .onConflict(uniqueFields)
348
- .merge(Object.keys(data).filter(f => !uniqueFields.includes(f)))
349
- .returning(meta?.comparableProps.filter(p => !p.lazy && !p.embeddable && !(p.name in data)).map(p => p.name) ?? '*');
348
+ .returning(returning);
349
+ if (!options.onConflictAction || options.onConflictAction === 'merge') {
350
+ const fields = (0, core_1.getOnConflictFields)(data, uniqueFields, options);
351
+ qb.merge(fields);
352
+ }
353
+ if (options.onConflictAction === 'ignore') {
354
+ qb.ignore();
355
+ }
350
356
  }
351
357
  else {
352
358
  qb.update(data).where(where);
@@ -363,12 +369,19 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
363
369
  options.convertCustomTypes ?? (options.convertCustomTypes = true);
364
370
  const meta = this.metadata.get(entityName);
365
371
  if (options.upsert) {
366
- const uniqueFields = core_1.Utils.isPlainObject(where[0]) ? Object.keys(where[0]) : meta.primaryKeys;
372
+ const uniqueFields = options.onConflictFields ?? (core_1.Utils.isPlainObject(where[0]) ? Object.keys(where[0]) : meta.primaryKeys);
367
373
  const qb = this.createQueryBuilder(entityName, options.ctx, 'write', options.convertCustomTypes).withSchema(this.getSchemaName(meta, options));
374
+ const returning = (0, core_1.getOnConflictReturningFields)(meta, data[0], uniqueFields, options);
368
375
  qb.insert(data)
369
376
  .onConflict(uniqueFields)
370
- .merge(Object.keys(data[0]).filter(f => !uniqueFields.includes(f)))
371
- .returning(meta.comparableProps.filter(p => !p.lazy && !p.embeddable && !(p.name in data[0])).map(p => p.name) ?? '*');
377
+ .returning(returning);
378
+ if (!options.onConflictAction || options.onConflictAction === 'merge') {
379
+ const fields = (0, core_1.getOnConflictFields)(data[0], uniqueFields, options);
380
+ qb.merge(fields);
381
+ }
382
+ if (options.onConflictAction === 'ignore') {
383
+ qb.ignore();
384
+ }
372
385
  return qb.execute('run', false);
373
386
  }
374
387
  const collections = options.processCollections ? data.map(d => this.extractManyToMany(entityName, d)) : [];
@@ -1,7 +1,5 @@
1
- import type { Constructor, EntityManager, EntityRepository, IDatabaseDriver, MikroORM } from '@mikro-orm/core';
2
- import { Platform } from '@mikro-orm/core';
3
- import type { SchemaHelper } from './schema';
4
- import { SchemaGenerator } from './schema';
1
+ import { Platform, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type MikroORM } from '@mikro-orm/core';
2
+ import { SchemaGenerator, type SchemaHelper } from './schema';
5
3
  export declare abstract class AbstractSqlPlatform extends Platform {
6
4
  protected readonly schemaHelper?: SchemaHelper;
7
5
  usesPivotTable(): boolean;
@@ -1,6 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { AnyEntity, ConnectionType, EntityData, EntityName, EntityRepository, GetRepository, QueryResult } from '@mikro-orm/core';
3
- import { EntityManager } from '@mikro-orm/core';
2
+ import { EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult } from '@mikro-orm/core';
4
3
  import type { AbstractSqlDriver } from './AbstractSqlDriver';
5
4
  import { QueryBuilder } from './query';
6
5
  import type { SqlEntityRepository } from './SqlEntityRepository';
@@ -1,6 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { ConnectionType, EntityName } from '@mikro-orm/core';
3
- import { EntityRepository } from '@mikro-orm/core';
2
+ import { EntityRepository, type ConnectionType, type EntityName } from '@mikro-orm/core';
4
3
  import type { SqlEntityManager } from './SqlEntityManager';
5
4
  import type { QueryBuilder } from './query';
6
5
  export declare class SqlEntityRepository<T extends object> extends EntityRepository<T> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.7.15-dev.43",
3
+ "version": "5.7.15-dev.44",
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.43",
70
- "@mikro-orm/entity-generator": "~5.7.15-dev.43",
71
- "@mikro-orm/migrations": "~5.7.15-dev.43",
69
+ "@mikro-orm/core": "~5.7.15-dev.44",
70
+ "@mikro-orm/entity-generator": "~5.7.15-dev.44",
71
+ "@mikro-orm/migrations": "~5.7.15-dev.44",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { inspect } from 'util';
3
- import type { EntityProperty, MetadataStorage } from '@mikro-orm/core';
3
+ import { type EntityProperty, type MetadataStorage } from '@mikro-orm/core';
4
4
  import type { ICriteriaNode, IQueryBuilder } from '../typings';
5
5
  /**
6
6
  * Helper for working with deeply nested where/orderBy/having criteria. Uses composite pattern to build tree from the payload.
@@ -1,4 +1,4 @@
1
- import type { Dictionary, EntityMetadata, MetadataStorage } from '@mikro-orm/core';
1
+ import { type Dictionary, type EntityMetadata, type MetadataStorage } from '@mikro-orm/core';
2
2
  import type { ICriteriaNode } from '../typings';
3
3
  /**
4
4
  * @internal
@@ -1,12 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { inspect } from 'util';
3
3
  import type { Knex } from 'knex';
4
- import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator, MetadataStorage, ObjectQuery, PopulateOptions, QBFilterQuery, QBQueryOrderMap, QueryResult, RequiredEntityData } from '@mikro-orm/core';
5
- import { LockMode, PopulateHint, QueryFlag } from '@mikro-orm/core';
4
+ import { LockMode, PopulateHint, QueryFlag, type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityName, type EntityProperty, type FlushMode, type GroupOperator, type MetadataStorage, type ObjectQuery, type PopulateOptions, type QBFilterQuery, type QBQueryOrderMap, type QueryResult, type RequiredEntityData } from '@mikro-orm/core';
6
5
  import { QueryType } from './enums';
7
6
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
8
- import type { Alias } from './QueryBuilderHelper';
9
- import { QueryBuilderHelper } from './QueryBuilderHelper';
7
+ import { QueryBuilderHelper, type Alias } from './QueryBuilderHelper';
10
8
  import type { SqlEntityManager } from '../SqlEntityManager';
11
9
  import type { Field } from '../typings';
12
10
  /**
@@ -1,6 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { Dictionary, EntityData, EntityMetadata, EntityProperty, FlatQueryOrderMap, QBFilterQuery } from '@mikro-orm/core';
3
- import { LockMode } from '@mikro-orm/core';
2
+ import { LockMode, type Dictionary, type EntityData, type EntityMetadata, type EntityProperty, type FlatQueryOrderMap, type QBFilterQuery } from '@mikro-orm/core';
4
3
  import { QueryType } from './enums';
5
4
  import type { Field, JoinOptions } from '../typings';
6
5
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
@@ -1,4 +1,4 @@
1
- import type { Configuration, Dictionary, EntityMetadata } from '@mikro-orm/core';
1
+ import { type Configuration, type Dictionary, type EntityMetadata } from '@mikro-orm/core';
2
2
  import { DatabaseTable } from './DatabaseTable';
3
3
  import type { AbstractSqlConnection } from '../AbstractSqlConnection';
4
4
  import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
@@ -1,4 +1,4 @@
1
- import type { Dictionary, EntityMetadata, EntityProperty, NamingStrategy } from '@mikro-orm/core';
1
+ import { type Dictionary, type EntityMetadata, type EntityProperty, type NamingStrategy } from '@mikro-orm/core';
2
2
  import type { SchemaHelper } from './SchemaHelper';
3
3
  import type { Check, Column, ForeignKey, Index } from '../typings';
4
4
  import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
@@ -1,5 +1,4 @@
1
- import type { MikroORM } from '@mikro-orm/core';
2
- import { AbstractSchemaGenerator } from '@mikro-orm/core';
1
+ import { AbstractSchemaGenerator, type MikroORM } from '@mikro-orm/core';
3
2
  import type { SchemaDifference } from '../typings';
4
3
  import { DatabaseSchema } from './DatabaseSchema';
5
4
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
@@ -1,5 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { Connection, Dictionary } from '@mikro-orm/core';
2
+ import { type Connection, type Dictionary } from '@mikro-orm/core';
3
3
  import type { AbstractSqlConnection } from '../AbstractSqlConnection';
4
4
  import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
5
5
  import type { Check, Column, Index, Table, TableDifference } from '../typings';