@mikro-orm/knex 6.2.9-dev.13 → 6.2.9-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.
@@ -28,6 +28,12 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
28
28
  nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
29
29
  nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
30
30
  nativeDelete<T extends object>(entityName: string, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
31
+ /**
32
+ * Fast comparison for collection snapshots that are represented by PK arrays.
33
+ * Compares scalars via `===` and fallbacks to Utils.equals()` for more complex types like Buffer.
34
+ * Always expects the same length of the arrays, since we only compare PKs of the same entity type.
35
+ */
36
+ private comparePrimaryKeyArrays;
31
37
  syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
32
38
  loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
33
39
  private getPivotOrderBy;
@@ -631,6 +631,26 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
631
631
  const qb = this.createQueryBuilder(entityName, options.ctx, 'write', false).delete(where).withSchema(this.getSchemaName(meta, options));
632
632
  return this.rethrow(qb.execute('run', false));
633
633
  }
634
+ /**
635
+ * Fast comparison for collection snapshots that are represented by PK arrays.
636
+ * Compares scalars via `===` and fallbacks to Utils.equals()` for more complex types like Buffer.
637
+ * Always expects the same length of the arrays, since we only compare PKs of the same entity type.
638
+ */
639
+ comparePrimaryKeyArrays(a, b) {
640
+ for (let i = a.length; i-- !== 0;) {
641
+ if (['number', 'string', 'bigint', 'boolean'].includes(typeof a[i])) {
642
+ if (a[i] !== b[i]) {
643
+ return false;
644
+ }
645
+ }
646
+ else {
647
+ if (!core_1.Utils.equals(a[i], b[i])) {
648
+ return false;
649
+ }
650
+ }
651
+ }
652
+ return true;
653
+ }
634
654
  async syncCollections(collections, options) {
635
655
  const groups = {};
636
656
  for (const coll of collections) {
@@ -638,7 +658,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
638
658
  const meta = wrapped.__meta;
639
659
  const pks = wrapped.getPrimaryKeys(true);
640
660
  const snap = coll.getSnapshot();
641
- const includes = (arr, item) => !!arr.find(i => core_1.Utils.equals(i, item));
661
+ const includes = (arr, item) => !!arr.find(i => this.comparePrimaryKeyArrays(i, item));
642
662
  const snapshot = snap ? snap.map(item => (0, core_1.helper)(item).getPrimaryKeys(true)) : [];
643
663
  const current = coll.getItems(false).map(item => (0, core_1.helper)(item).getPrimaryKeys(true));
644
664
  const deleteDiff = snap ? snapshot.filter(item => !includes(current, item)) : true;
@@ -648,8 +668,12 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
648
668
  // wrong order if we just delete and insert to the end (only owning sides can have fixed order)
649
669
  if (coll.property.owner && coll.property.fixedOrder && !equals && Array.isArray(deleteDiff)) {
650
670
  deleteDiff.length = insertDiff.length = 0;
651
- deleteDiff.push(...snapshot);
652
- insertDiff.push(...current);
671
+ for (const item of snapshot) {
672
+ deleteDiff.push(item);
673
+ }
674
+ for (const item of current) {
675
+ insertDiff.push(item);
676
+ }
653
677
  }
654
678
  if (coll.property.kind === core_1.ReferenceKind.ONE_TO_MANY) {
655
679
  const cols = coll.property.referencedColumnNames;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.2.9-dev.13",
3
+ "version": "6.2.9-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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^6.2.8"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.2.9-dev.13"
69
+ "@mikro-orm/core": "6.2.9-dev.15"
70
70
  }
71
71
  }