@mikro-orm/core 7.1.0-dev.34 → 7.1.0-dev.36

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.
package/EntityManager.js CHANGED
@@ -656,7 +656,7 @@ export class EntityManager {
656
656
  where = await em.processWhere(entityName, where, options, 'read');
657
657
  validateEmptyWhere(where);
658
658
  em.checkLockRequirements(options.lockMode, meta);
659
- const isOptimisticLocking = options.lockMode == null || options.lockMode === LockMode.OPTIMISTIC;
659
+ const isOptimisticLocking = options.lockMode == null || options.lockMode === LockMode.NONE || options.lockMode === LockMode.OPTIMISTIC;
660
660
  if (entity && !em.shouldRefresh(meta, entity, options) && isOptimisticLocking) {
661
661
  return em.lockAndPopulate(meta, entity, where, options);
662
662
  }
@@ -690,8 +690,11 @@ export class EntityLoader {
690
690
  }
691
691
  return ret;
692
692
  }, []);
693
- // we need to automatically select the FKs too, e.g. for 1:m relations to be able to wire them with the items
694
- if (prop.kind === ReferenceKind.ONE_TO_MANY || prop.kind === ReferenceKind.MANY_TO_MANY) {
693
+ // we need to automatically select the FKs too, e.g. for 1:m and inverse 1:1 relations
694
+ // to be able to wire them with the items
695
+ if (prop.kind === ReferenceKind.ONE_TO_MANY ||
696
+ prop.kind === ReferenceKind.MANY_TO_MANY ||
697
+ (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner)) {
695
698
  const owner = prop.targetMeta.properties[prop.mappedBy];
696
699
  // when the owning FK is lazy, we need to explicitly select it even without user-provided fields,
697
700
  // otherwise the driver will exclude it and we won't be able to map children to their parent collections
@@ -1603,7 +1603,7 @@ export class MetadataDiscovery {
1603
1603
  const table = this.createSchemaTable(meta);
1604
1604
  for (const check of meta.checks) {
1605
1605
  const fieldNames = check.property ? meta.properties[check.property].fieldNames : [];
1606
- check.name ??= this.#namingStrategy.indexName(meta.tableName, fieldNames, 'check');
1606
+ check.name ??= this.#platform.getIndexName(meta.tableName, fieldNames, 'check');
1607
1607
  if (check.expression instanceof Function) {
1608
1608
  check.expression = check.expression(columns, table);
1609
1609
  }
@@ -1628,7 +1628,7 @@ export class MetadataDiscovery {
1628
1628
  }
1629
1629
  if (expression) {
1630
1630
  meta.checks.push({
1631
- name: this.#namingStrategy.indexName(meta.tableName, prop.fieldNames, 'check'),
1631
+ name: this.#platform.getIndexName(meta.tableName, prop.fieldNames, 'check'),
1632
1632
  property: prop.name,
1633
1633
  expression,
1634
1634
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.0-dev.34",
3
+ "version": "7.1.0-dev.36",
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",
@@ -278,9 +278,17 @@ export declare abstract class Platform {
278
278
  /** Whether the platform supports unsigned integer columns. */
279
279
  supportsUnsigned(): boolean;
280
280
  /**
281
- * Returns the default name of index for the given columns
281
+ * Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
282
+ * Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
283
+ * `Infinity` (no truncation); SQL platforms override with their engine's limit
284
+ * (PG 63, MySQL/MariaDB 64, MSSQL/Oracle 128).
282
285
  */
283
- getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence'): string;
286
+ getMaxIdentifierLength(): number;
287
+ /**
288
+ * Returns the default name of index for the given columns, hash-truncated if it would
289
+ * exceed {@link getMaxIdentifierLength}.
290
+ */
291
+ getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence' | 'check'): string;
284
292
  /** Returns the default primary key constraint name. */
285
293
  getDefaultPrimaryName(tableName: string, columns: string[]): string;
286
294
  /** Whether the platform supports custom names for primary key constraints. */
@@ -630,10 +630,26 @@ export class Platform {
630
630
  return false;
631
631
  }
632
632
  /**
633
- * Returns the default name of index for the given columns
633
+ * Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
634
+ * Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
635
+ * `Infinity` (no truncation); SQL platforms override with their engine's limit
636
+ * (PG 63, MySQL/MariaDB 64, MSSQL/Oracle 128).
637
+ */
638
+ getMaxIdentifierLength() {
639
+ return Infinity;
640
+ }
641
+ /**
642
+ * Returns the default name of index for the given columns, hash-truncated if it would
643
+ * exceed {@link getMaxIdentifierLength}.
634
644
  */
635
645
  getIndexName(tableName, columns, type) {
636
- return this.namingStrategy.indexName(tableName, columns, type);
646
+ const indexName = this.namingStrategy.indexName(tableName, columns, type);
647
+ const max = this.getMaxIdentifierLength();
648
+ if (indexName.length > max) {
649
+ const suffix = type === 'primary' ? 'pkey' : type;
650
+ return `${indexName.substring(0, max - 8 - type.length)}_${Utils.hash(indexName, 5)}_${suffix}`;
651
+ }
652
+ return indexName;
637
653
  }
638
654
  /** Returns the default primary key constraint name. */
639
655
  getDefaultPrimaryName(tableName, columns) {
package/typings.js CHANGED
@@ -193,9 +193,10 @@ export class EntityMetadata {
193
193
  // Virtual entities evaluate expressions at query time, view entities create actual database views.
194
194
  this.virtual = !!this.expression && !this.view;
195
195
  if (config) {
196
+ const platform = config.getPlatform();
196
197
  for (const prop of this.props) {
197
198
  if (prop.enum && !prop.nativeEnumName && prop.items?.every(item => typeof item === 'string')) {
198
- const name = config.getNamingStrategy().indexName(this.tableName, prop.fieldNames, 'check');
199
+ const name = platform.getIndexName(this.tableName, prop.fieldNames, 'check');
199
200
  const exists = this.checks.findIndex(check => check.name === name);
200
201
  if (exists !== -1) {
201
202
  this.checks.splice(exists, 1);
@@ -203,9 +204,7 @@ export class EntityMetadata {
203
204
  this.checks.push({
204
205
  name,
205
206
  property: prop.name,
206
- expression: config
207
- .getPlatform()
208
- .getEnumCheckConstraintExpression(prop.fieldNames[0], prop.items),
207
+ expression: platform.getEnumCheckConstraintExpression(prop.fieldNames[0], prop.items),
209
208
  });
210
209
  }
211
210
  }
@@ -470,7 +470,7 @@ export class UnitOfWork {
470
470
  if (options.lockMode === LockMode.OPTIMISTIC) {
471
471
  await this.lockOptimistic(entity, meta, options.lockVersion);
472
472
  }
473
- else if (options.lockMode != null) {
473
+ else if (options.lockMode != null && options.lockMode !== LockMode.NONE) {
474
474
  await this.lockPessimistic(entity, options);
475
475
  }
476
476
  }
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.1.0-dev.34';
144
+ static #ORM_VERSION = '7.1.0-dev.36';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */