@mikro-orm/sql 7.0.3-dev.0 → 7.0.3-dev.10

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,4 +1,4 @@
1
- import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type FormulaTable, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, type Raw, RawQueryFragment, type StreamOptions, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
1
+ import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type FormulaTable, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type Primary, type QueryOrderMap, type QueryResult, type Raw, RawQueryFragment, type StreamOptions, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
2
2
  import type { AbstractSqlConnection } from './AbstractSqlConnection.js';
3
3
  import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js';
4
4
  import { type AnyQueryBuilder } from './query/QueryBuilder.js';
@@ -23,8 +23,8 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
23
23
  private validateSqlOptions;
24
24
  createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
25
25
  private createQueryBuilderFromOptions;
26
- find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: EntityName<T>, where: ObjectQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
27
- findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: EntityName<T>, where: ObjectQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
26
+ find<T extends object, P extends string = never, F extends string = never, E extends string = never>(entityName: EntityName<T>, where: ObjectQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
27
+ findOne<T extends object, P extends string = never, F extends string = never, E extends string = never>(entityName: EntityName<T>, where: ObjectQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
28
28
  protected hasToManyJoins<T extends object>(hint: PopulateOptions<T>, meta: EntityMetadata<T>): boolean;
29
29
  findVirtual<T extends object>(entityName: EntityName<T>, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
30
30
  countVirtual<T extends object>(entityName: EntityName<T>, where: ObjectQuery<T>, options: CountOptions<T, any>): Promise<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.0.3-dev.0",
3
+ "version": "7.0.3-dev.10",
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
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.0.3-dev.0"
56
+ "@mikro-orm/core": "7.0.3-dev.10"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -57,6 +57,18 @@ export declare class SchemaComparator {
57
57
  */
58
58
  private compareArrays;
59
59
  diffExpression(expr1: string, expr2: string): boolean;
60
+ /**
61
+ * Compares two view expressions, with special handling for SELECT *.
62
+ * Databases like PostgreSQL and MySQL expand `SELECT *` to explicit column names
63
+ * in their stored view definitions, which makes diffExpression always detect changes.
64
+ * When SELECT * is present, we strip the first SELECT...FROM column list from both
65
+ * sides and compare only the structural parts (FROM clause onwards).
66
+ * Note: this means changes *within* subqueries in the SELECT list of a SELECT * view
67
+ * may not be detected — an acceptable tradeoff since SELECT * views are inherently
68
+ * column-list-agnostic.
69
+ * @see https://github.com/mikro-orm/mikro-orm/issues/7308
70
+ */
71
+ private diffViewExpression;
60
72
  parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
61
73
  hasSameDefaultValue(from: Column, to: Column): boolean;
62
74
  private mapColumnToProperty;
@@ -123,7 +123,7 @@ export class SchemaComparator {
123
123
  }
124
124
  else {
125
125
  const fromView = fromSchema.getView(toView.name) ?? fromSchema.getView(viewName);
126
- if (fromView && this.diffExpression(fromView.definition, toView.definition)) {
126
+ if (fromView && this.diffViewExpression(fromView.definition, toView.definition)) {
127
127
  diff.changedViews[viewName] = { from: fromView, to: toView };
128
128
  this.log(`view ${viewName} changed`);
129
129
  }
@@ -666,6 +666,28 @@ export class SchemaComparator {
666
666
  };
667
667
  return simplify(expr1) !== simplify(expr2);
668
668
  }
669
+ /**
670
+ * Compares two view expressions, with special handling for SELECT *.
671
+ * Databases like PostgreSQL and MySQL expand `SELECT *` to explicit column names
672
+ * in their stored view definitions, which makes diffExpression always detect changes.
673
+ * When SELECT * is present, we strip the first SELECT...FROM column list from both
674
+ * sides and compare only the structural parts (FROM clause onwards).
675
+ * Note: this means changes *within* subqueries in the SELECT list of a SELECT * view
676
+ * may not be detected — an acceptable tradeoff since SELECT * views are inherently
677
+ * column-list-agnostic.
678
+ * @see https://github.com/mikro-orm/mikro-orm/issues/7308
679
+ */
680
+ diffViewExpression(fromDef, toDef) {
681
+ if (!this.diffExpression(fromDef, toDef)) {
682
+ return false;
683
+ }
684
+ // If either expression uses SELECT *, the diff may be due to * expansion
685
+ if (/\bselect\s+\*/i.test(fromDef) || /\bselect\s+\*/i.test(toDef)) {
686
+ const stripColumns = (s) => s.replace(/\bselect\b[\s\S]*?\bfrom\b/i, 'select from');
687
+ return this.diffExpression(stripColumns(fromDef), stripColumns(toDef));
688
+ }
689
+ return true;
690
+ }
669
691
  parseJsonDefault(defaultValue) {
670
692
  /* v8 ignore next */
671
693
  if (!defaultValue) {