@mikro-orm/knex 5.0.0-rc.1 → 6.0.0-dev.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +661 -0
  2. package/{AbstractSqlConnection.d.ts → dist/AbstractSqlConnection.d.ts} +0 -0
  3. package/{AbstractSqlConnection.js → dist/AbstractSqlConnection.js} +0 -0
  4. package/{AbstractSqlDriver.d.ts → dist/AbstractSqlDriver.d.ts} +3 -2
  5. package/{AbstractSqlDriver.js → dist/AbstractSqlDriver.js} +16 -7
  6. package/{AbstractSqlPlatform.d.ts → dist/AbstractSqlPlatform.d.ts} +0 -0
  7. package/{AbstractSqlPlatform.js → dist/AbstractSqlPlatform.js} +0 -0
  8. package/dist/LICENSE +21 -0
  9. package/{MonkeyPatchable.d.ts → dist/MonkeyPatchable.d.ts} +0 -0
  10. package/{MonkeyPatchable.js → dist/MonkeyPatchable.js} +0 -0
  11. package/{README.md → dist/README.md} +0 -0
  12. package/{SqlEntityManager.d.ts → dist/SqlEntityManager.d.ts} +0 -0
  13. package/{SqlEntityManager.js → dist/SqlEntityManager.js} +0 -0
  14. package/{SqlEntityRepository.d.ts → dist/SqlEntityRepository.d.ts} +0 -0
  15. package/{SqlEntityRepository.js → dist/SqlEntityRepository.js} +0 -0
  16. package/{index.d.ts → dist/index.d.ts} +0 -0
  17. package/{index.js → dist/index.js} +0 -0
  18. package/{index.mjs → dist/index.mjs} +0 -0
  19. package/dist/package.json +99 -0
  20. package/{query → dist/query}/ArrayCriteriaNode.d.ts +0 -0
  21. package/{query → dist/query}/ArrayCriteriaNode.js +0 -0
  22. package/{query → dist/query}/CriteriaNode.d.ts +0 -0
  23. package/{query → dist/query}/CriteriaNode.js +7 -3
  24. package/{query → dist/query}/CriteriaNodeFactory.d.ts +0 -0
  25. package/{query → dist/query}/CriteriaNodeFactory.js +0 -0
  26. package/{query → dist/query}/ObjectCriteriaNode.d.ts +0 -0
  27. package/{query → dist/query}/ObjectCriteriaNode.js +0 -0
  28. package/{query → dist/query}/QueryBuilder.d.ts +0 -0
  29. package/{query → dist/query}/QueryBuilder.js +1 -1
  30. package/{query → dist/query}/QueryBuilderHelper.d.ts +1 -1
  31. package/{query → dist/query}/QueryBuilderHelper.js +20 -3
  32. package/{query → dist/query}/ScalarCriteriaNode.d.ts +0 -0
  33. package/{query → dist/query}/ScalarCriteriaNode.js +0 -0
  34. package/{query → dist/query}/enums.d.ts +0 -0
  35. package/{query → dist/query}/enums.js +0 -0
  36. package/{query → dist/query}/index.d.ts +0 -0
  37. package/{query → dist/query}/index.js +0 -0
  38. package/{schema → dist/schema}/DatabaseSchema.d.ts +0 -0
  39. package/{schema → dist/schema}/DatabaseSchema.js +9 -1
  40. package/{schema → dist/schema}/DatabaseTable.d.ts +2 -5
  41. package/{schema → dist/schema}/DatabaseTable.js +1 -1
  42. package/{schema → dist/schema}/SchemaComparator.d.ts +0 -0
  43. package/{schema → dist/schema}/SchemaComparator.js +4 -0
  44. package/{schema → dist/schema}/SchemaGenerator.d.ts +0 -0
  45. package/{schema → dist/schema}/SchemaGenerator.js +0 -0
  46. package/{schema → dist/schema}/SchemaHelper.d.ts +0 -0
  47. package/{schema → dist/schema}/SchemaHelper.js +2 -2
  48. package/{schema → dist/schema}/index.d.ts +0 -0
  49. package/{schema → dist/schema}/index.js +0 -0
  50. package/{typings.d.ts → dist/typings.d.ts} +3 -3
  51. package/{typings.js → dist/typings.js} +0 -0
  52. package/package.json +16 -14
@@ -23,7 +23,6 @@ export declare abstract class AbstractSqlDriver<C extends AbstractSqlConnection
23
23
  nativeInsert<T extends AnyEntity<T>>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
24
24
  nativeInsertMany<T extends AnyEntity<T>>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
25
25
  nativeUpdate<T extends AnyEntity<T>>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
26
- private getSchemaName;
27
26
  nativeUpdateMany<T extends AnyEntity<T>>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
28
27
  nativeDelete<T extends AnyEntity<T>>(entityName: string, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
29
28
  syncCollection<T extends AnyEntity<T>, O extends AnyEntity<O>>(coll: Collection<T, O>, options?: DriverMethodOptions): Promise<void>;
@@ -47,7 +46,9 @@ export declare abstract class AbstractSqlDriver<C extends AbstractSqlConnection
47
46
  protected createQueryBuilder<T extends AnyEntity<T>>(entityName: string, ctx?: Transaction<Knex.Transaction>, write?: boolean, convertCustomTypes?: boolean): QueryBuilder<T>;
48
47
  protected extractManyToMany<T extends AnyEntity<T>>(entityName: string, data: EntityDictionary<T>): EntityData<T>;
49
48
  protected processManyToMany<T extends AnyEntity<T>>(meta: EntityMetadata<T> | undefined, pks: Primary<T>[], collections: EntityData<T>, clear: boolean, options?: DriverMethodOptions): Promise<void>;
50
- protected updateCollectionDiff<T extends AnyEntity<T>, O extends AnyEntity<O>>(meta: EntityMetadata<O>, prop: EntityProperty<T>, pks: Primary<O>[], deleteDiff: Primary<T>[][] | boolean, insertDiff: Primary<T>[][], options?: DriverMethodOptions): Promise<void>;
49
+ protected updateCollectionDiff<T extends AnyEntity<T>, O extends AnyEntity<O>>(meta: EntityMetadata<O>, prop: EntityProperty<T>, pks: Primary<O>[], deleteDiff: Primary<T>[][] | boolean, insertDiff: Primary<T>[][], options?: DriverMethodOptions & {
50
+ ownerSchema?: string;
51
+ }): Promise<void>;
51
52
  lockPessimistic<T extends AnyEntity<T>>(entity: T, options: LockOptions): Promise<void>;
52
53
  protected buildJoinedPropsOrderBy<T extends AnyEntity<T>>(entityName: string, qb: QueryBuilder<T>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], parentPath?: string): QueryOrderMap<T>[];
53
54
  protected buildFields<T extends AnyEntity<T>>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T>, fields?: Field<T>[]): Field<T>[];
@@ -183,7 +183,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
183
183
  res = await this.rethrow(qb.insert(data).execute('run', false));
184
184
  }
185
185
  else {
186
- let sql = `insert into ${(this.getTableName(meta, options))} `;
186
+ let sql = `insert into ${this.getTableName(meta, options)} `;
187
187
  /* istanbul ignore next */
188
188
  sql += fields.length > 0 ? '(' + fields.map(k => this.platform.quoteIdentifier(k)).join(', ') + ')' : 'default';
189
189
  sql += ` values `;
@@ -252,10 +252,6 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
252
252
  await this.processManyToMany(meta, pk, collections, true, options);
253
253
  return res;
254
254
  }
255
- getSchemaName(meta, options) {
256
- /* istanbul ignore next */
257
- return options?.schema === '*' ? this.config.get('schema') : options?.schema ?? (meta?.schema === '*' ? this.config.get('schema') : meta?.schema);
258
- }
259
255
  async nativeUpdateMany(entityName, where, data, options = {}) {
260
256
  options.processCollections ?? (options.processCollections = true);
261
257
  options.convertCustomTypes ?? (options.convertCustomTypes = true);
@@ -350,11 +346,20 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
350
346
  if (coll.property.reference === core_1.ReferenceType.ONE_TO_MANY) {
351
347
  const cols = coll.property.referencedColumnNames;
352
348
  const qb = this.createQueryBuilder(coll.property.type, ctx, true)
349
+ .withSchema(this.getSchemaName(meta, options))
353
350
  .update({ [coll.property.mappedBy]: pks })
354
351
  .getKnexQuery()
355
352
  .whereIn(cols, insertDiff);
356
353
  return this.rethrow(this.execute(qb));
357
354
  }
355
+ /* istanbul ignore next */
356
+ const ownerSchema = wrapped.getSchema() === '*' ? this.config.get('schema') : wrapped.getSchema();
357
+ const pivotMeta = this.metadata.find(coll.property.pivotTable);
358
+ if (pivotMeta.schema === '*') {
359
+ /* istanbul ignore next */
360
+ options ?? (options = {});
361
+ options.schema = ownerSchema;
362
+ }
358
363
  return this.rethrow(this.updateCollectionDiff(meta, coll.property, pks, deleteDiff, insertDiff, options));
359
364
  }
360
365
  async loadFromPivotTable(prop, owners, where = {}, orderBy, ctx, options) {
@@ -369,7 +374,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
369
374
  where = { ...where, ...cond };
370
375
  }
371
376
  orderBy = this.getPivotOrderBy(prop, orderBy);
372
- const qb = this.createQueryBuilder(prop.type, ctx, !!ctx).unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES).withSchema(options?.schema);
377
+ const qb = this.createQueryBuilder(prop.type, ctx, !!ctx)
378
+ .unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES)
379
+ .withSchema(this.getSchemaName(prop.targetMeta, options));
373
380
  const populate = this.autoJoinOneToOneOwner(prop.targetMeta, [{ field: prop.pivotTable }]);
374
381
  const fields = this.buildFields(prop.targetMeta, (options?.populate ?? []), [], qb, options?.fields);
375
382
  qb.select(fields).populate(populate).where(where).orderBy(orderBy).setLockMode(options?.lockMode, options?.lockTableAliases);
@@ -534,7 +541,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
534
541
  deleteDiff = [];
535
542
  }
536
543
  if (deleteDiff === true || deleteDiff.length > 0) {
537
- const qb1 = this.createQueryBuilder(prop.pivotTable, options?.ctx, true).withSchema(this.getSchemaName(meta, options)).unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES);
544
+ const qb1 = this.createQueryBuilder(prop.pivotTable, options?.ctx, true)
545
+ .withSchema(this.getSchemaName(meta, options))
546
+ .unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES);
538
547
  const knex = qb1.getKnex();
539
548
  if (Array.isArray(deleteDiff)) {
540
549
  knex.whereIn(prop.inverseJoinColumns, deleteDiff);
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Martin Adámek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@mikro-orm/knex",
3
+ "version": "5.0.0",
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
+ "main": "index.js",
6
+ "module": "index.mjs",
7
+ "typings": "index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "import": "./index.mjs",
12
+ "require": "./index.js"
13
+ }
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
18
+ },
19
+ "keywords": [
20
+ "orm",
21
+ "mongo",
22
+ "mongodb",
23
+ "mysql",
24
+ "mariadb",
25
+ "postgresql",
26
+ "sqlite",
27
+ "sqlite3",
28
+ "ts",
29
+ "typescript",
30
+ "js",
31
+ "javascript",
32
+ "entity",
33
+ "ddd",
34
+ "mikro-orm",
35
+ "unit-of-work",
36
+ "data-mapper",
37
+ "identity-map"
38
+ ],
39
+ "author": "Martin Adámek",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/mikro-orm/mikro-orm/issues"
43
+ },
44
+ "homepage": "https://mikro-orm.io",
45
+ "engines": {
46
+ "node": ">= 14.0.0"
47
+ },
48
+ "scripts": {
49
+ "build": "yarn clean && yarn compile && yarn copy",
50
+ "postbuild": "yarn gen-esm-wrapper index.js index.mjs",
51
+ "clean": "rimraf ./dist",
52
+ "compile": "tsc -p tsconfig.build.json",
53
+ "copy": "ts-node -T ../../scripts/copy.ts"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "dependencies": {
59
+ "fs-extra": "10.0.0",
60
+ "knex": "1.0.1",
61
+ "sqlstring": "2.3.2"
62
+ },
63
+ "devDependencies": {
64
+ "@mikro-orm/core": "^5.0.0"
65
+ },
66
+ "peerDependencies": {
67
+ "@mikro-orm/core": "^5.0.0",
68
+ "@mikro-orm/entity-generator": "^5.0.0",
69
+ "@mikro-orm/migrations": "^5.0.0",
70
+ "@vscode/sqlite3": "^5.0.0",
71
+ "mssql": "^7.0.0",
72
+ "mysql": "^2.18.1",
73
+ "mysql2": "^2.1.0",
74
+ "pg": "^8.0.3"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "@mikro-orm/entity-generator": {
78
+ "optional": true
79
+ },
80
+ "@mikro-orm/migrations": {
81
+ "optional": true
82
+ },
83
+ "@vscode/sqlite3": {
84
+ "optional": true
85
+ },
86
+ "mssql": {
87
+ "optional": true
88
+ },
89
+ "mysql": {
90
+ "optional": true
91
+ },
92
+ "mysql2": {
93
+ "optional": true
94
+ },
95
+ "pg": {
96
+ "optional": true
97
+ }
98
+ }
99
+ }
File without changes
File without changes
File without changes
@@ -16,7 +16,11 @@ class CriteriaNode {
16
16
  this.key = key;
17
17
  const meta = parent && metadata.find(parent.entityName);
18
18
  if (meta && key) {
19
- core_1.Utils.splitPrimaryKeys(key).forEach(k => {
19
+ const pks = core_1.Utils.splitPrimaryKeys(key);
20
+ if (pks.length > 1) {
21
+ return;
22
+ }
23
+ pks.forEach(k => {
20
24
  this.prop = meta.props.find(prop => prop.name === k || (prop.fieldNames || []).includes(k));
21
25
  // do not validate if the key is prefixed or type casted (e.g. `k::text`)
22
26
  if (validate && !this.prop && !k.includes('.') && !k.includes('::') && !core_1.Utils.isOperator(k) && !CriteriaNode.isCustomExpression(k)) {
@@ -52,12 +56,12 @@ class CriteriaNode {
52
56
  }
53
57
  }
54
58
  renameFieldToPK(qb) {
55
- const alias = qb.getAliasForJoinPath(this.getPath());
59
+ const alias = qb.getAliasForJoinPath(this.getPath()) ?? qb.alias;
56
60
  if (this.prop.reference === core_1.ReferenceType.MANY_TO_MANY) {
57
61
  return core_1.Utils.getPrimaryKeyHash(this.prop.inverseJoinColumns.map(col => `${alias}.${col}`));
58
62
  }
59
63
  if (this.prop.joinColumns.length > 1) {
60
- return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns);
64
+ return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${alias}.${col}`));
61
65
  }
62
66
  return core_1.Utils.getPrimaryKeyHash(this.prop.referencedColumnNames.map(col => `${alias}.${col}`));
63
67
  }
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -279,7 +279,7 @@ class QueryBuilder {
279
279
  return qb.orderByRaw(queryOrder);
280
280
  }
281
281
  }, this._orderBy);
282
- core_1.Utils.runIfNotEmpty(() => qb.limit(this._limit), this._limit);
282
+ core_1.Utils.runIfNotEmpty(() => qb.limit(this._limit), this._limit != null);
283
283
  core_1.Utils.runIfNotEmpty(() => qb.offset(this._offset), this._offset);
284
284
  core_1.Utils.runIfNotEmpty(() => this.helper.appendOnConflictClause(this.type, this._onConflict, qb), this._onConflict);
285
285
  if (this.type === enums_1.QueryType.TRUNCATE && this.platform.usesCascadeStatement()) {
@@ -1,5 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { Dictionary, EntityMetadata, EntityProperty, FlatQueryOrderMap, MetadataStorage, Platform, EntityData, QBFilterQuery } from '@mikro-orm/core';
2
+ import type { Dictionary, EntityData, EntityMetadata, EntityProperty, FlatQueryOrderMap, MetadataStorage, Platform, QBFilterQuery } from '@mikro-orm/core';
3
3
  import { LockMode } from '@mikro-orm/core';
4
4
  import { QueryType } from './enums';
5
5
  import type { Field, JoinOptions } from '../typings';
@@ -21,7 +21,18 @@ class QueryBuilderHelper {
21
21
  const isTableNameAliasRequired = this.isTableNameAliasRequired(type);
22
22
  const fields = core_1.Utils.splitPrimaryKeys(field);
23
23
  if (fields.length > 1) {
24
- return this.knex.raw('(' + fields.map(f => this.knex.ref(this.mapper(f, type, value, alias))).join(', ') + ')');
24
+ const parts = [];
25
+ for (const p of fields) {
26
+ const [a, f] = this.splitField(p);
27
+ const prop = this.getProperty(f, a);
28
+ if (prop) {
29
+ parts.push(...prop.fieldNames.map(f => this.mapper(f, type, value, alias)));
30
+ }
31
+ else {
32
+ parts.push(this.mapper(`${a}.${f}`, type, value, alias));
33
+ }
34
+ }
35
+ return this.knex.raw('(' + parts.map(part => this.knex.ref(part)).join(', ') + ')');
25
36
  }
26
37
  let ret = field;
27
38
  const customExpression = QueryBuilderHelper.isCustomExpression(field, !!alias);
@@ -31,13 +42,19 @@ class QueryBuilderHelper {
31
42
  if (prop?.fieldNameRaw) {
32
43
  return this.knex.raw(this.prefix(field, isTableNameAliasRequired));
33
44
  }
45
+ if (prop?.formula) {
46
+ const alias2 = this.knex.ref(a).toString();
47
+ const aliased = this.knex.ref(prop.fieldNames[0]).toString();
48
+ const as = alias === null ? '' : ` as ${aliased}`;
49
+ return this.knex.raw(`${prop.formula(alias2)}${as}`);
50
+ }
34
51
  if (prop?.customType?.convertToJSValueSQL) {
35
52
  const prefixed = this.prefix(field, isTableNameAliasRequired, true);
36
53
  const valueSQL = prop.customType.convertToJSValueSQL(prefixed, this.platform);
37
54
  if (alias === null) {
38
55
  return this.knex.raw(valueSQL);
39
56
  }
40
- return this.knex.raw(valueSQL + ' as ' + this.platform.quoteIdentifier(alias ?? prop.fieldNames[0]));
57
+ return this.knex.raw(`${valueSQL} as ${this.platform.quoteIdentifier(alias ?? prop.fieldNames[0])}`);
41
58
  }
42
59
  // do not wrap custom expressions
43
60
  if (!customExpression) {
@@ -147,7 +164,7 @@ class QueryBuilderHelper {
147
164
  Object.values(joins).forEach(join => {
148
165
  let table = `${join.table} as ${join.alias}`;
149
166
  const method = join.type === 'pivotJoin' ? 'leftJoin' : join.type;
150
- schema = join.schema ?? schema;
167
+ schema = join.schema && join.schema !== '*' ? join.schema : schema;
151
168
  if (schema) {
152
169
  table = `${schema}.${table}`;
153
170
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -67,7 +67,15 @@ class DatabaseSchema {
67
67
  meta.indexes.forEach(index => table.addIndex(meta, index, 'index'));
68
68
  meta.uniques.forEach(index => table.addIndex(meta, index, 'unique'));
69
69
  table.addIndex(meta, { properties: meta.props.filter(prop => prop.primary).map(prop => prop.name) }, 'primary');
70
- meta.checks.forEach(check => table.addCheck(check));
70
+ meta.checks.forEach(check => {
71
+ const columnName = check.property ? meta.properties[check.property].fieldNames[0] : undefined;
72
+ table.addCheck({
73
+ name: check.name,
74
+ expression: check.expression,
75
+ definition: `check ((${check.expression}))`,
76
+ columnName,
77
+ });
78
+ });
71
79
  }
72
80
  return schema;
73
81
  }
@@ -32,7 +32,7 @@ export declare class DatabaseTable {
32
32
  hasColumn(columnName: string): boolean;
33
33
  getIndex(indexName: string): Index | undefined;
34
34
  hasIndex(indexName: string): boolean;
35
- getCheck(checkName: string): Check | undefined;
35
+ getCheck(checkName: string): Check<unknown> | undefined;
36
36
  hasCheck(checkName: string): boolean;
37
37
  getPrimaryKey(): Index | undefined;
38
38
  hasPrimaryKey(): boolean;
@@ -48,9 +48,6 @@ export declare class DatabaseTable {
48
48
  expression?: string;
49
49
  options?: Dictionary;
50
50
  }, type: 'index' | 'unique' | 'primary'): void;
51
- addCheck(check: {
52
- name: string;
53
- expression: string;
54
- }): void;
51
+ addCheck(check: Check): void;
55
52
  toJSON(): Dictionary;
56
53
  }
@@ -288,7 +288,7 @@ class DatabaseTable {
288
288
  }
289
289
  addIndex(meta, index, type) {
290
290
  const properties = core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => meta.properties[prop].fieldNames));
291
- if (properties.length === 0) {
291
+ if (properties.length === 0 && !index.expression) {
292
292
  return;
293
293
  }
294
294
  const name = this.getIndexName(index.name, properties, type);
File without changes
@@ -347,6 +347,10 @@ class SchemaComparator {
347
347
  * Compares index1 with index2 and returns index2 if there are any differences or false in case there are no differences.
348
348
  */
349
349
  diffIndex(index1, index2) {
350
+ // if one of them is a custom expression, compare only by name
351
+ if (index1.expression || index2.expression) {
352
+ return index1.keyName !== index2.keyName;
353
+ }
350
354
  return !this.isIndexFulfilledBy(index1, index2) || !this.isIndexFulfilledBy(index2, index1);
351
355
  }
352
356
  /**
File without changes
File without changes
File without changes
@@ -7,7 +7,7 @@ class SchemaHelper {
7
7
  this.platform = platform;
8
8
  }
9
9
  getSchemaBeginning(charset) {
10
- return `${this.disableForeignKeysSQL()}`;
10
+ return `${this.disableForeignKeysSQL()}\n\n`;
11
11
  }
12
12
  disableForeignKeysSQL() {
13
13
  return '';
@@ -16,7 +16,7 @@ class SchemaHelper {
16
16
  return '';
17
17
  }
18
18
  getSchemaEnd() {
19
- return `${this.enableForeignKeysSQL()}`;
19
+ return `${this.enableForeignKeysSQL()}\n`;
20
20
  }
21
21
  finalizeTable(table, charset, collate) {
22
22
  //
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { Dictionary, EntityProperty, GroupOperator, QBFilterQuery, QueryOrderMap, Type } from '@mikro-orm/core';
2
+ import type { CheckCallback, Dictionary, EntityProperty, GroupOperator, QBFilterQuery, QueryOrderMap, Type } from '@mikro-orm/core';
3
3
  import type { QueryType } from './query/enums';
4
4
  import type { DatabaseSchema, DatabaseTable } from './schema';
5
5
  export interface Table {
@@ -65,9 +65,9 @@ export interface Index {
65
65
  predicate?: Knex.QueryBuilder;
66
66
  }>;
67
67
  }
68
- export interface Check {
68
+ export interface Check<T = unknown> {
69
69
  name: string;
70
- expression: string;
70
+ expression: string | CheckCallback<T>;
71
71
  definition?: string;
72
72
  columnName?: string;
73
73
  }
File without changes
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.0.0-rc.1",
3
+ "version": "6.0.0-dev.0+4ab7bdd0ca",
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
- "main": "index.js",
6
- "module": "index.mjs",
7
- "typings": "index.d.ts",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "typings": "dist/index.d.ts",
8
8
  "exports": {
9
+ "./package.json": "./package.json",
9
10
  ".": {
10
- "import": "./index.mjs",
11
- "require": "./index.js"
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "repository": {
@@ -46,7 +47,7 @@
46
47
  },
47
48
  "scripts": {
48
49
  "build": "yarn clean && yarn compile && yarn copy",
49
- "postbuild": "yarn gen-esm-wrapper index.js index.mjs",
50
+ "postbuild": "yarn gen-esm-wrapper dist/index.js dist/index.mjs",
50
51
  "clean": "rimraf ./dist",
51
52
  "compile": "tsc -p tsconfig.build.json",
52
53
  "copy": "ts-node -T ../../scripts/copy.ts"
@@ -60,17 +61,17 @@
60
61
  "sqlstring": "2.3.2"
61
62
  },
62
63
  "devDependencies": {
63
- "@mikro-orm/core": "^5.0.0-rc.1"
64
+ "@mikro-orm/core": "^6.0.0-dev.0+4ab7bdd0ca"
64
65
  },
65
66
  "peerDependencies": {
66
- "@mikro-orm/core": "^5.0.0-rc.1",
67
- "@mikro-orm/entity-generator": "^5.0.0-rc.1",
68
- "@mikro-orm/migrations": "^5.0.0-rc.1",
67
+ "@mikro-orm/core": "^5.0.0",
68
+ "@mikro-orm/entity-generator": "^5.0.0",
69
+ "@mikro-orm/migrations": "^5.0.0",
70
+ "@vscode/sqlite3": "^5.0.0",
69
71
  "mssql": "^7.0.0",
70
72
  "mysql": "^2.18.1",
71
73
  "mysql2": "^2.1.0",
72
- "pg": "^8.0.3",
73
- "@vscode/sqlite3": "^5.0.0"
74
+ "pg": "^8.0.3"
74
75
  },
75
76
  "peerDependenciesMeta": {
76
77
  "@mikro-orm/entity-generator": {
@@ -94,5 +95,6 @@
94
95
  "pg": {
95
96
  "optional": true
96
97
  }
97
- }
98
+ },
99
+ "gitHead": "4ab7bdd0caf4f80b6a646dcd66c5ac6b67308764"
98
100
  }