@mikro-orm/knex 6.0.0-dev.5 → 6.0.0-dev.51
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/AbstractSqlConnection.d.ts +3 -0
- package/AbstractSqlConnection.js +16 -8
- package/AbstractSqlDriver.d.ts +11 -11
- package/AbstractSqlDriver.js +107 -44
- package/AbstractSqlPlatform.d.ts +2 -4
- package/AbstractSqlPlatform.js +15 -21
- package/MonkeyPatchable.d.ts +1 -0
- package/MonkeyPatchable.js +3 -0
- package/README.md +63 -106
- package/SqlEntityManager.d.ts +0 -4
- package/SqlEntityManager.js +1 -9
- package/SqlEntityRepository.d.ts +0 -1
- package/SqlEntityRepository.js +0 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.mjs +175 -0
- package/package.json +5 -39
- package/query/ArrayCriteriaNode.d.ts +3 -3
- package/query/CriteriaNode.d.ts +8 -8
- package/query/CriteriaNode.js +8 -8
- package/query/CriteriaNodeFactory.d.ts +6 -6
- package/query/CriteriaNodeFactory.js +11 -11
- package/query/ObjectCriteriaNode.d.ts +3 -3
- package/query/ObjectCriteriaNode.js +12 -8
- package/query/QueryBuilder.d.ts +17 -4
- package/query/QueryBuilder.js +188 -45
- package/query/QueryBuilderHelper.d.ts +3 -5
- package/query/QueryBuilderHelper.js +85 -71
- package/query/ScalarCriteriaNode.d.ts +3 -2
- package/query/ScalarCriteriaNode.js +9 -6
- package/schema/DatabaseSchema.js +3 -3
- package/schema/DatabaseTable.d.ts +9 -9
- package/schema/DatabaseTable.js +21 -22
- package/schema/SchemaComparator.d.ts +4 -4
- package/schema/SchemaComparator.js +4 -2
- package/schema/SchemaHelper.d.ts +11 -11
- package/schema/SchemaHelper.js +3 -3
- package/schema/{SchemaGenerator.d.ts → SqlSchemaGenerator.d.ts} +4 -8
- package/schema/{SchemaGenerator.js → SqlSchemaGenerator.js} +17 -24
- package/schema/index.d.ts +1 -1
- package/schema/index.js +1 -1
- package/typings.d.ts +14 -13
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type { MikroORM } from '@mikro-orm/core';
|
|
1
|
+
import type { MikroORM, ISchemaGenerator } from '@mikro-orm/core';
|
|
2
2
|
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> {
|
|
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<
|
|
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
|
|
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
|
-
|
|
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
|
|
158
|
-
options.safe
|
|
159
|
-
options.dropTables
|
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
482
|
+
exports.SqlSchemaGenerator = SqlSchemaGenerator;
|
|
483
|
+
exports.SchemaGenerator = SqlSchemaGenerator;
|
package/schema/index.d.ts
CHANGED
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("./
|
|
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
|
|
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
|
|
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<
|
|
92
|
-
changedIndexes: Dictionary<
|
|
93
|
-
removedIndexes: Dictionary<
|
|
94
|
-
renamedIndexes: Dictionary<
|
|
95
|
-
addedChecks: Dictionary<
|
|
96
|
-
changedChecks: Dictionary<
|
|
97
|
-
removedChecks: Dictionary<
|
|
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
|
|
147
|
+
process(qb: IQueryBuilder<T>, alias?: string): any;
|
|
147
148
|
shouldInline(payload: any): boolean;
|
|
148
|
-
willAutoJoin
|
|
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;
|