@mikro-orm/knex 6.4.17-dev.29 → 6.4.17-dev.30

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/index.mjs CHANGED
@@ -226,6 +226,7 @@ export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
226
226
  export const helper = mod.helper;
227
227
  export const knex = mod.knex;
228
228
  export const parseJsonSafe = mod.parseJsonSafe;
229
+ export const quote = mod.quote;
229
230
  export const raw = mod.raw;
230
231
  export const ref = mod.ref;
231
232
  export const rel = mod.rel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.4.17-dev.29",
3
+ "version": "6.4.17-dev.30",
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,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.4.16"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.4.17-dev.29",
69
+ "@mikro-orm/core": "6.4.17-dev.30",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -1,4 +1,4 @@
1
- import { type Configuration, type DeferMode, type Dictionary, type EntityMetadata, type EntityProperty, type NamingStrategy } from '@mikro-orm/core';
1
+ import { type Configuration, type DeferMode, type Dictionary, type EntityMetadata, type EntityProperty, type NamingStrategy, type IndexCallback } from '@mikro-orm/core';
2
2
  import type { SchemaHelper } from './SchemaHelper';
3
3
  import type { CheckDef, Column, ForeignKey, IndexDef } from '../typings';
4
4
  import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
@@ -53,12 +53,13 @@ export declare class DatabaseTable {
53
53
  private getPropertyTypeForForeignKey;
54
54
  private getPropertyTypeForColumn;
55
55
  private getPropertyDefaultValue;
56
+ private processIndexExpression;
56
57
  addIndex(meta: EntityMetadata, index: {
57
- properties: string | string[];
58
+ properties?: string | string[];
58
59
  name?: string;
59
60
  type?: string;
60
- expression?: string;
61
- deferMode?: DeferMode;
61
+ expression?: string | IndexCallback<any>;
62
+ deferMode?: DeferMode | `${DeferMode}`;
62
63
  options?: Dictionary;
63
64
  }, type: 'index' | 'unique' | 'primary'): void;
64
65
  addCheck(check: CheckDef): void;
@@ -700,6 +700,18 @@ class DatabaseTable {
700
700
  }
701
701
  return '' + val;
702
702
  }
703
+ processIndexExpression(expression, meta) {
704
+ if (expression instanceof Function) {
705
+ const exp = expression({ name: this.name, schema: this.schema, toString() {
706
+ if (this.schema) {
707
+ return `${this.schema}.${this.name}`;
708
+ }
709
+ return this.name;
710
+ } }, meta.createColumnMappingObject());
711
+ return exp instanceof core_1.RawQueryFragment ? this.platform.formatQuery(exp.sql, exp.params) : exp;
712
+ }
713
+ return expression;
714
+ }
703
715
  addIndex(meta, index, type) {
704
716
  const properties = core_1.Utils.unique(core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => {
705
717
  const parts = prop.split('.');
@@ -741,7 +753,7 @@ class DatabaseTable {
741
753
  primary: type === 'primary',
742
754
  unique: type !== 'index',
743
755
  type: index.type,
744
- expression: index.expression,
756
+ expression: this.processIndexExpression(index.expression, meta),
745
757
  options: index.options,
746
758
  deferMode: index.deferMode,
747
759
  });
package/typings.d.ts CHANGED
@@ -75,7 +75,7 @@ export interface IndexDef {
75
75
  storageEngineIndexType?: 'hash' | 'btree';
76
76
  predicate?: Knex.QueryBuilder;
77
77
  }>;
78
- deferMode?: DeferMode;
78
+ deferMode?: DeferMode | `${DeferMode}`;
79
79
  }
80
80
  export interface CheckDef<T = unknown> {
81
81
  name: string;