@mikro-orm/core 7.1.0-dev.14 → 7.1.0-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.
@@ -644,6 +644,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
644
644
  type?: string;
645
645
  options?: Dictionary;
646
646
  expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK, TBase>>;
647
+ where?: string | FilterQuery<InferEntityFromProperties<TProperties, TPK, TBase>>;
647
648
  columns?: IndexColumnOptions[];
648
649
  include?: NoInfer<AllKeys<TProperties, TBase>> | NoInfer<AllKeys<TProperties, TBase>>[];
649
650
  fillFactor?: number;
@@ -656,6 +657,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
656
657
  name?: string;
657
658
  options?: Dictionary;
658
659
  expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK, TBase>>;
660
+ where?: string | FilterQuery<InferEntityFromProperties<TProperties, TPK, TBase>>;
659
661
  deferMode?: DeferMode | `${DeferMode}`;
660
662
  columns?: IndexColumnOptions[];
661
663
  include?: NoInfer<AllKeys<TProperties, TBase>> | NoInfer<AllKeys<TProperties, TBase>>[];
@@ -551,6 +551,16 @@ interface BaseOptions<T, H extends string> {
551
551
  include?: T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>;
552
552
  /** Fill factor for the index as a percentage 0-100 (PostgreSQL, MSSQL). */
553
553
  fillFactor?: number;
554
+ /**
555
+ * Predicate for partial indexes. Object form is a `FilterQuery` and is portable across
556
+ * SQL drivers and MongoDB; string form is a raw SQL fragment (SQL drivers only).
557
+ *
558
+ * Native support: PostgreSQL, SQLite, MSSQL (`WHERE`), MongoDB (`partialFilterExpression`).
559
+ * MySQL 8.0.13+ / Oracle: emulated via `CASE WHEN` functional index (uniqueness only enforced
560
+ * where the predicate holds). MariaDB is not supported — it has no inline expression indexes;
561
+ * define a virtual generated column and index that instead.
562
+ */
563
+ where?: string | (T extends EntityClass<infer P> ? FilterQuery<P> : FilterQuery<T>);
554
564
  }
555
565
  export interface UniqueOptions<T, H extends string = string> extends BaseOptions<T, H> {
556
566
  deferMode?: DeferMode | `${DeferMode}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.0-dev.14",
3
+ "version": "7.1.0-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
  "keywords": [
6
6
  "data-mapper",
package/typings.d.ts CHANGED
@@ -912,6 +912,7 @@ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> =
912
912
  type?: string;
913
913
  options?: Dictionary;
914
914
  expression?: string | IndexCallback<Entity>;
915
+ where?: string | FilterQuery<Entity>;
915
916
  columns?: IndexColumnOptions[];
916
917
  include?: EntityKey<Entity> | EntityKey<Entity>[];
917
918
  fillFactor?: number;
@@ -924,6 +925,7 @@ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> =
924
925
  name?: string;
925
926
  options?: Dictionary;
926
927
  expression?: string | IndexCallback<Entity>;
928
+ where?: string | FilterQuery<Entity>;
927
929
  deferMode?: DeferMode | `${DeferMode}`;
928
930
  columns?: IndexColumnOptions[];
929
931
  include?: EntityKey<Entity> | EntityKey<Entity>[];
package/typings.js CHANGED
@@ -261,8 +261,8 @@ export class EntityMetadata {
261
261
  }, { __gettersDefined: { value: true, enumerable: false } });
262
262
  }
263
263
  initIndexes(prop) {
264
- const simpleIndex = this.indexes.find(index => index.properties === prop.name && !index.options && !index.type && !index.expression);
265
- const simpleUnique = this.uniques.find(index => index.properties === prop.name && !index.options);
264
+ const simpleIndex = this.indexes.find(index => index.properties === prop.name && !index.options && !index.type && !index.expression && index.where == null);
265
+ const simpleUnique = this.uniques.find(index => index.properties === prop.name && !index.options && !index.expression && index.where == null);
266
266
  const owner = prop.kind === ReferenceKind.MANY_TO_ONE;
267
267
  if (!prop.index && simpleIndex) {
268
268
  Utils.defaultValue(simpleIndex, 'name', true);
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.14';
144
+ static #ORM_VERSION = '7.1.0-dev.15';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */