@mikro-orm/knex 6.0.0-dev.6 → 6.0.0-dev.61

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 (42) hide show
  1. package/AbstractSqlConnection.d.ts +5 -2
  2. package/AbstractSqlConnection.js +18 -10
  3. package/AbstractSqlDriver.d.ts +17 -17
  4. package/AbstractSqlDriver.js +110 -47
  5. package/AbstractSqlPlatform.d.ts +2 -2
  6. package/AbstractSqlPlatform.js +14 -7
  7. package/MonkeyPatchable.d.ts +1 -0
  8. package/MonkeyPatchable.js +3 -0
  9. package/README.md +64 -107
  10. package/SqlEntityManager.d.ts +0 -4
  11. package/SqlEntityManager.js +1 -9
  12. package/SqlEntityRepository.d.ts +0 -1
  13. package/SqlEntityRepository.js +0 -1
  14. package/index.d.ts +1 -0
  15. package/index.js +1 -0
  16. package/index.mjs +176 -0
  17. package/package.json +5 -5
  18. package/query/ArrayCriteriaNode.d.ts +3 -3
  19. package/query/CriteriaNode.d.ts +8 -8
  20. package/query/CriteriaNode.js +8 -8
  21. package/query/CriteriaNodeFactory.d.ts +6 -6
  22. package/query/CriteriaNodeFactory.js +11 -11
  23. package/query/ObjectCriteriaNode.d.ts +3 -3
  24. package/query/ObjectCriteriaNode.js +12 -8
  25. package/query/QueryBuilder.d.ts +19 -5
  26. package/query/QueryBuilder.js +191 -47
  27. package/query/QueryBuilderHelper.d.ts +3 -5
  28. package/query/QueryBuilderHelper.js +85 -71
  29. package/query/ScalarCriteriaNode.d.ts +3 -2
  30. package/query/ScalarCriteriaNode.js +9 -6
  31. package/schema/DatabaseSchema.js +3 -3
  32. package/schema/DatabaseTable.d.ts +9 -9
  33. package/schema/DatabaseTable.js +21 -22
  34. package/schema/SchemaComparator.d.ts +4 -4
  35. package/schema/SchemaComparator.js +4 -2
  36. package/schema/SchemaHelper.d.ts +11 -11
  37. package/schema/SchemaHelper.js +3 -3
  38. package/schema/{SchemaGenerator.d.ts → SqlSchemaGenerator.d.ts} +3 -7
  39. package/schema/{SchemaGenerator.js → SqlSchemaGenerator.js} +17 -24
  40. package/schema/index.d.ts +1 -1
  41. package/schema/index.js +1 -1
  42. package/typings.d.ts +14 -13
@@ -3,16 +3,11 @@ import { AbstractSchemaGenerator } from '@mikro-orm/core';
3
3
  import type { SchemaDifference } from '../typings';
4
4
  import { DatabaseSchema } from './DatabaseSchema';
5
5
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
6
- /**
7
- * Should be renamed to `SqlSchemaGenerator` in v6
8
- */
9
- export declare class SchemaGenerator extends AbstractSchemaGenerator<AbstractSqlDriver> implements ISchemaGenerator {
6
+ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<AbstractSqlDriver> implements ISchemaGenerator {
10
7
  private readonly helper;
11
8
  private readonly options;
12
9
  protected lastEnsuredDatabase?: string;
13
10
  static register(orm: MikroORM): void;
14
- /** @deprecated use `dropSchema` and `createSchema` commands respectively */
15
- generate(): Promise<string>;
16
11
  createSchema(options?: {
17
12
  wrap?: boolean;
18
13
  schema?: string;
@@ -88,7 +83,7 @@ export declare class SchemaGenerator extends AbstractSchemaGenerator<AbstractSql
88
83
  dropDatabase(name: string): Promise<void>;
89
84
  execute(sql: string, options?: {
90
85
  wrap?: boolean;
91
- }): Promise<undefined>;
86
+ }): Promise<void>;
92
87
  private wrapSchema;
93
88
  private createSchemaBuilder;
94
89
  private createTable;
@@ -101,3 +96,4 @@ export declare class SchemaGenerator extends AbstractSchemaGenerator<AbstractSql
101
96
  private dump;
102
97
  private get knex();
103
98
  }
99
+ export { SqlSchemaGenerator as SchemaGenerator };
@@ -1,28 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchemaGenerator = void 0;
3
+ exports.SchemaGenerator = exports.SqlSchemaGenerator = void 0;
4
4
  const core_1 = require("@mikro-orm/core");
5
5
  const DatabaseSchema_1 = require("./DatabaseSchema");
6
6
  const SchemaComparator_1 = require("./SchemaComparator");
7
- /**
8
- * Should be renamed to `SqlSchemaGenerator` in v6
9
- */
10
- class SchemaGenerator extends core_1.AbstractSchemaGenerator {
7
+ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
11
8
  constructor() {
12
9
  super(...arguments);
13
10
  this.helper = this.platform.getSchemaHelper();
14
11
  this.options = this.config.get('schemaGenerator');
15
12
  }
16
13
  static register(orm) {
17
- orm.config.registerExtension('@mikro-orm/schema-generator', () => new SchemaGenerator(orm.em));
18
- }
19
- /** @deprecated use `dropSchema` and `createSchema` commands respectively */
20
- async generate() {
21
- const [dropSchema, createSchema] = await Promise.all([
22
- this.getDropSchemaSQL({ wrap: false }),
23
- this.getCreateSchemaSQL({ wrap: false }),
24
- ]);
25
- return this.wrapSchema(dropSchema + createSchema);
14
+ orm.config.registerExtension('@mikro-orm/schema-generator', () => new SqlSchemaGenerator(orm.em));
26
15
  }
27
16
  async createSchema(options) {
28
17
  await this.ensureDatabase();
@@ -143,7 +132,9 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
143
132
  return this.diffToSQL(diffUp, options);
144
133
  }
145
134
  async getUpdateSchemaMigrationSQL(options = {}) {
146
- await this.ensureDatabase();
135
+ if (!options.fromSchema) {
136
+ await this.ensureDatabase();
137
+ }
147
138
  const { fromSchema, toSchema } = await this.prepareSchemaForComparison(options);
148
139
  const comparator = new SchemaComparator_1.SchemaComparator(this.platform);
149
140
  const diffUp = comparator.compare(fromSchema, toSchema);
@@ -154,9 +145,9 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
154
145
  };
155
146
  }
156
147
  async prepareSchemaForComparison(options) {
157
- options.wrap ?? (options.wrap = this.options.disableForeignKeys);
158
- options.safe ?? (options.safe = false);
159
- options.dropTables ?? (options.dropTables = true);
148
+ options.wrap ??= this.options.disableForeignKeys;
149
+ options.safe ??= false;
150
+ options.dropTables ??= true;
160
151
  const toSchema = this.getTargetSchema(options.schema);
161
152
  const fromSchema = options.fromSchema ?? await DatabaseSchema_1.DatabaseSchema.create(this.connection, this.platform, this.config, options.schema);
162
153
  const wildcardSchemaTables = Object.values(this.metadata.getAll()).filter(meta => meta.schema === '*').map(meta => meta.tableName);
@@ -305,13 +296,13 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
305
296
  this.helper.configureColumn(column, col, this.knex, changedProperties);
306
297
  }
307
298
  for (const { column } of Object.values(diff.changedColumns).filter(diff => diff.changedProperties.has('autoincrement'))) {
308
- this.helper.pushTableQuery(table, this.helper.getAlterColumnAutoincrement(tableName, column));
299
+ this.helper.pushTableQuery(table, this.helper.getAlterColumnAutoincrement(tableName, column, schemaName));
309
300
  }
310
301
  for (const { column, changedProperties } of Object.values(diff.changedColumns).filter(diff => diff.changedProperties.has('comment'))) {
311
302
  if (['type', 'nullable', 'autoincrement', 'unsigned', 'default', 'enumItems'].some(t => changedProperties.has(t))) {
312
303
  continue; // will be handled via knex
313
304
  }
314
- this.helper.pushTableQuery(table, this.helper.getChangeColumnCommentSQL(tableName, column));
305
+ this.helper.pushTableQuery(table, this.helper.getChangeColumnCommentSQL(tableName, column, schemaName));
315
306
  }
316
307
  for (const [oldColumnName, column] of Object.entries(diff.renamedColumns)) {
317
308
  this.helper.pushTableQuery(table, this.helper.getRenameColumnSQL(tableName, oldColumnName, column, schemaName));
@@ -364,19 +355,20 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
364
355
  await this.driver.execute(this.helper.getDropDatabaseSQL('' + this.knex.ref(name)));
365
356
  }
366
357
  async execute(sql, options = {}) {
367
- options.wrap ?? (options.wrap = false);
358
+ options.wrap ??= false;
368
359
  const lines = this.wrapSchema(sql, options).split('\n').filter(i => i.trim());
369
360
  if (lines.length === 0) {
370
361
  return;
371
362
  }
372
363
  if (this.platform.supportsMultipleStatements()) {
373
364
  const query = lines.join('\n');
374
- return void await this.driver.execute(query);
365
+ await this.driver.execute(query);
366
+ return;
375
367
  }
376
368
  await core_1.Utils.runSerial(lines, line => this.driver.execute(line));
377
369
  }
378
370
  wrapSchema(sql, options = {}) {
379
- options.wrap ?? (options.wrap = this.options.disableForeignKeys);
371
+ options.wrap ??= this.options.disableForeignKeys;
380
372
  if (!options.wrap || sql.trim() === '') {
381
373
  return sql;
382
374
  }
@@ -487,4 +479,5 @@ class SchemaGenerator extends core_1.AbstractSchemaGenerator {
487
479
  return this.connection.getKnex();
488
480
  }
489
481
  }
490
- exports.SchemaGenerator = SchemaGenerator;
482
+ exports.SqlSchemaGenerator = SqlSchemaGenerator;
483
+ exports.SchemaGenerator = SqlSchemaGenerator;
package/schema/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './DatabaseSchema';
2
2
  export * from './DatabaseTable';
3
- export * from './SchemaGenerator';
3
+ export * from './SqlSchemaGenerator';
4
4
  export * from './SchemaHelper';
5
5
  export * from './SchemaComparator';
package/schema/index.js CHANGED
@@ -16,6 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./DatabaseSchema"), exports);
18
18
  __exportStar(require("./DatabaseTable"), exports);
19
- __exportStar(require("./SchemaGenerator"), exports);
19
+ __exportStar(require("./SqlSchemaGenerator"), exports);
20
20
  __exportStar(require("./SchemaHelper"), exports);
21
21
  __exportStar(require("./SchemaComparator"), exports);
package/typings.d.ts CHANGED
@@ -25,6 +25,7 @@ export interface JoinOptions {
25
25
  path?: string;
26
26
  prop: EntityProperty;
27
27
  cond: Dictionary;
28
+ cond_?: Dictionary;
28
29
  }
29
30
  export interface Column {
30
31
  name: string;
@@ -54,7 +55,7 @@ export interface ForeignKey {
54
55
  updateRule?: string;
55
56
  deleteRule?: string;
56
57
  }
57
- export interface Index {
58
+ export interface IndexDef {
58
59
  columnNames: string[];
59
60
  keyName: string;
60
61
  unique: boolean;
@@ -67,7 +68,7 @@ export interface Index {
67
68
  predicate?: Knex.QueryBuilder;
68
69
  }>;
69
70
  }
70
- export interface Check<T = unknown> {
71
+ export interface CheckDef<T = unknown> {
71
72
  name: string;
72
73
  expression: string | CheckCallback<T>;
73
74
  definition?: string;
@@ -88,13 +89,13 @@ export interface TableDifference {
88
89
  changedColumns: Dictionary<ColumnDifference>;
89
90
  removedColumns: Dictionary<Column>;
90
91
  renamedColumns: Dictionary<Column>;
91
- addedIndexes: Dictionary<Index>;
92
- changedIndexes: Dictionary<Index>;
93
- removedIndexes: Dictionary<Index>;
94
- renamedIndexes: Dictionary<Index>;
95
- addedChecks: Dictionary<Check>;
96
- changedChecks: Dictionary<Check>;
97
- removedChecks: Dictionary<Check>;
92
+ addedIndexes: Dictionary<IndexDef>;
93
+ changedIndexes: Dictionary<IndexDef>;
94
+ removedIndexes: Dictionary<IndexDef>;
95
+ renamedIndexes: Dictionary<IndexDef>;
96
+ addedChecks: Dictionary<CheckDef>;
97
+ changedChecks: Dictionary<CheckDef>;
98
+ removedChecks: Dictionary<CheckDef>;
98
99
  addedForeignKeys: Dictionary<ForeignKey>;
99
100
  changedForeignKeys: Dictionary<ForeignKey>;
100
101
  removedForeignKeys: Dictionary<ForeignKey>;
@@ -136,16 +137,16 @@ export interface IQueryBuilder<T> {
136
137
  getAliasForJoinPath(path: string): string | undefined;
137
138
  getNextAlias(entityName?: string): string;
138
139
  }
139
- export interface ICriteriaNode {
140
+ export interface ICriteriaNode<T extends object> {
140
141
  readonly entityName: string;
141
- readonly parent?: ICriteriaNode | undefined;
142
+ readonly parent?: ICriteriaNode<T> | undefined;
142
143
  readonly key?: string | undefined;
143
144
  payload: any;
144
145
  prop?: EntityProperty;
145
146
  index?: number;
146
- process<T>(qb: IQueryBuilder<T>, alias?: string): any;
147
+ process(qb: IQueryBuilder<T>, alias?: string): any;
147
148
  shouldInline(payload: any): boolean;
148
- willAutoJoin<T>(qb: IQueryBuilder<T>, alias?: string): boolean;
149
+ willAutoJoin(qb: IQueryBuilder<T>, alias?: string): boolean;
149
150
  shouldRename(payload: any): boolean;
150
151
  renameFieldToPK<T>(qb: IQueryBuilder<T>): string;
151
152
  getPath(addIndex?: boolean): string;