@mikro-orm/knex 6.0.0-dev.29 → 6.0.0-dev.291
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 +22 -4
- package/AbstractSqlConnection.js +48 -18
- package/AbstractSqlDriver.d.ts +30 -24
- package/AbstractSqlDriver.js +596 -274
- package/AbstractSqlPlatform.d.ts +9 -4
- package/AbstractSqlPlatform.js +40 -5
- package/MonkeyPatchable.d.ts +1 -0
- package/MonkeyPatchable.js +3 -0
- package/PivotCollectionPersister.d.ts +17 -0
- package/PivotCollectionPersister.js +128 -0
- package/README.md +64 -107
- package/SqlEntityManager.d.ts +4 -8
- package/SqlEntityManager.js +8 -12
- package/SqlEntityRepository.d.ts +7 -6
- package/SqlEntityRepository.js +11 -8
- package/index.mjs +22 -3
- package/package.json +8 -8
- package/query/ArrayCriteriaNode.d.ts +3 -2
- package/query/ArrayCriteriaNode.js +7 -2
- package/query/CriteriaNode.d.ts +6 -4
- package/query/CriteriaNode.js +22 -9
- package/query/CriteriaNodeFactory.d.ts +1 -1
- package/query/CriteriaNodeFactory.js +27 -11
- package/query/ObjectCriteriaNode.d.ts +3 -2
- package/query/ObjectCriteriaNode.js +72 -28
- package/query/QueryBuilder.d.ts +58 -26
- package/query/QueryBuilder.js +438 -142
- package/query/QueryBuilderHelper.d.ts +13 -18
- package/query/QueryBuilderHelper.js +190 -163
- package/query/ScalarCriteriaNode.d.ts +3 -2
- package/query/ScalarCriteriaNode.js +14 -4
- package/query/enums.d.ts +7 -0
- package/query/enums.js +10 -2
- package/schema/DatabaseSchema.d.ts +5 -2
- package/schema/DatabaseSchema.js +26 -8
- package/schema/DatabaseTable.d.ts +12 -4
- package/schema/DatabaseTable.js +369 -44
- package/schema/SchemaComparator.d.ts +7 -5
- package/schema/SchemaComparator.js +68 -35
- package/schema/SchemaHelper.d.ts +7 -5
- package/schema/SchemaHelper.js +25 -11
- package/schema/SqlSchemaGenerator.d.ts +3 -4
- package/schema/SqlSchemaGenerator.js +71 -28
- package/typings.d.ts +27 -8
package/query/enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryType = void 0;
|
|
3
|
+
exports.JoinType = exports.QueryType = void 0;
|
|
4
4
|
var QueryType;
|
|
5
5
|
(function (QueryType) {
|
|
6
6
|
QueryType["TRUNCATE"] = "TRUNCATE";
|
|
@@ -9,4 +9,12 @@ var QueryType;
|
|
|
9
9
|
QueryType["INSERT"] = "INSERT";
|
|
10
10
|
QueryType["UPDATE"] = "UPDATE";
|
|
11
11
|
QueryType["DELETE"] = "DELETE";
|
|
12
|
-
})(QueryType
|
|
12
|
+
})(QueryType || (exports.QueryType = QueryType = {}));
|
|
13
|
+
var JoinType;
|
|
14
|
+
(function (JoinType) {
|
|
15
|
+
JoinType["leftJoin"] = "left join";
|
|
16
|
+
JoinType["innerJoin"] = "inner join";
|
|
17
|
+
JoinType["pivotJoin"] = "pivot join";
|
|
18
|
+
JoinType["innerJoinLateral"] = "inner join lateral";
|
|
19
|
+
JoinType["leftJoinLateral"] = "left join lateral";
|
|
20
|
+
})(JoinType || (exports.JoinType = JoinType = {}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Configuration, type Dictionary, type EntityMetadata } from '@mikro-orm/core';
|
|
2
2
|
import { DatabaseTable } from './DatabaseTable';
|
|
3
3
|
import type { AbstractSqlConnection } from '../AbstractSqlConnection';
|
|
4
4
|
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
|
|
@@ -10,14 +10,17 @@ export declare class DatabaseSchema {
|
|
|
10
10
|
readonly name: string;
|
|
11
11
|
private tables;
|
|
12
12
|
private namespaces;
|
|
13
|
+
private nativeEnums;
|
|
13
14
|
constructor(platform: AbstractSqlPlatform, name: string);
|
|
14
15
|
addTable(name: string, schema: string | undefined | null, comment?: string): DatabaseTable;
|
|
15
16
|
getTables(): DatabaseTable[];
|
|
16
17
|
getTable(name: string): DatabaseTable | undefined;
|
|
17
18
|
hasTable(name: string): boolean;
|
|
19
|
+
setNativeEnums(nativeEnums: Dictionary<unknown[]>): void;
|
|
20
|
+
getNativeEnums(): Dictionary<unknown[]>;
|
|
18
21
|
hasNamespace(namespace: string): boolean;
|
|
19
22
|
getNamespaces(): string[];
|
|
20
|
-
static create(connection: AbstractSqlConnection, platform: AbstractSqlPlatform, config: Configuration, schemaName?: string): Promise<DatabaseSchema>;
|
|
23
|
+
static create(connection: AbstractSqlConnection, platform: AbstractSqlPlatform, config: Configuration, schemaName?: string, schemas?: string[]): Promise<DatabaseSchema>;
|
|
21
24
|
static fromMetadata(metadata: EntityMetadata[], platform: AbstractSqlPlatform, config: Configuration, schemaName?: string): DatabaseSchema;
|
|
22
25
|
private static getSchemaName;
|
|
23
26
|
private static shouldHaveColumn;
|
package/schema/DatabaseSchema.js
CHANGED
|
@@ -7,15 +7,19 @@ const DatabaseTable_1 = require("./DatabaseTable");
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
class DatabaseSchema {
|
|
10
|
+
platform;
|
|
11
|
+
name;
|
|
12
|
+
tables = [];
|
|
13
|
+
namespaces = new Set();
|
|
14
|
+
nativeEnums = {}; // for postgres
|
|
10
15
|
constructor(platform, name) {
|
|
11
16
|
this.platform = platform;
|
|
12
17
|
this.name = name;
|
|
13
|
-
this.tables = [];
|
|
14
|
-
this.namespaces = new Set();
|
|
15
18
|
}
|
|
16
19
|
addTable(name, schema, comment) {
|
|
17
20
|
const namespaceName = schema ?? this.name;
|
|
18
21
|
const table = new DatabaseTable_1.DatabaseTable(this.platform, name, namespaceName);
|
|
22
|
+
table.nativeEnums = this.nativeEnums;
|
|
19
23
|
table.comment = comment;
|
|
20
24
|
this.tables.push(table);
|
|
21
25
|
if (namespaceName != null) {
|
|
@@ -32,30 +36,44 @@ class DatabaseSchema {
|
|
|
32
36
|
hasTable(name) {
|
|
33
37
|
return !!this.getTable(name);
|
|
34
38
|
}
|
|
39
|
+
setNativeEnums(nativeEnums) {
|
|
40
|
+
this.nativeEnums = nativeEnums;
|
|
41
|
+
this.tables.forEach(t => t.nativeEnums = nativeEnums);
|
|
42
|
+
}
|
|
43
|
+
getNativeEnums() {
|
|
44
|
+
return this.nativeEnums;
|
|
45
|
+
}
|
|
35
46
|
hasNamespace(namespace) {
|
|
36
47
|
return this.namespaces.has(namespace);
|
|
37
48
|
}
|
|
38
49
|
getNamespaces() {
|
|
39
50
|
return [...this.namespaces];
|
|
40
51
|
}
|
|
41
|
-
static async create(connection, platform, config, schemaName) {
|
|
42
|
-
const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema'));
|
|
52
|
+
static async create(connection, platform, config, schemaName, schemas) {
|
|
53
|
+
const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema') ?? platform.getDefaultSchemaName());
|
|
43
54
|
const allTables = await connection.execute(platform.getSchemaHelper().getListTablesSQL());
|
|
44
55
|
const parts = config.get('migrations').tableName.split('.');
|
|
45
56
|
const migrationsTableName = parts[1] ?? parts[0];
|
|
46
57
|
const migrationsSchemaName = parts.length > 1 ? parts[0] : config.get('schema', platform.getDefaultSchemaName());
|
|
47
58
|
const tables = allTables.filter(t => t.table_name !== migrationsTableName || (t.schema_name && t.schema_name !== migrationsSchemaName));
|
|
48
|
-
await platform.getSchemaHelper().loadInformationSchema(schema, connection, tables);
|
|
59
|
+
await platform.getSchemaHelper().loadInformationSchema(schema, connection, tables, schemas && schemas.length > 0 ? schemas : undefined);
|
|
49
60
|
return schema;
|
|
50
61
|
}
|
|
51
62
|
static fromMetadata(metadata, platform, config, schemaName) {
|
|
52
63
|
const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema'));
|
|
64
|
+
const nativeEnums = {};
|
|
65
|
+
for (const meta of metadata) {
|
|
66
|
+
meta.props
|
|
67
|
+
.filter(prop => prop.nativeEnumName)
|
|
68
|
+
.forEach(prop => nativeEnums[prop.nativeEnumName] = prop.items?.map(val => '' + val) ?? []);
|
|
69
|
+
}
|
|
70
|
+
schema.setNativeEnums(nativeEnums);
|
|
53
71
|
for (const meta of metadata) {
|
|
54
72
|
const table = schema.addTable(meta.collection, this.getSchemaName(meta, config, schemaName));
|
|
55
73
|
table.comment = meta.comment;
|
|
56
74
|
meta.props
|
|
57
75
|
.filter(prop => this.shouldHaveColumn(meta, prop))
|
|
58
|
-
.forEach(prop => table.addColumnFromProperty(prop, meta));
|
|
76
|
+
.forEach(prop => table.addColumnFromProperty(prop, meta, config));
|
|
59
77
|
meta.indexes.forEach(index => table.addIndex(meta, index, 'index'));
|
|
60
78
|
meta.uniques.forEach(index => table.addIndex(meta, index, 'unique'));
|
|
61
79
|
table.addIndex(meta, { properties: meta.props.filter(prop => prop.primary).map(prop => prop.name) }, 'primary');
|
|
@@ -75,10 +93,10 @@ class DatabaseSchema {
|
|
|
75
93
|
return (meta.schema === '*' ? schema : meta.schema) ?? config.get('schema');
|
|
76
94
|
}
|
|
77
95
|
static shouldHaveColumn(meta, prop) {
|
|
78
|
-
if (prop.persist === false ||
|
|
96
|
+
if (prop.persist === false || (prop.columnTypes?.length ?? 0) === 0) {
|
|
79
97
|
return false;
|
|
80
98
|
}
|
|
81
|
-
if (meta.pivotTable || (core_1.ReferenceKind.EMBEDDED && prop.object)) {
|
|
99
|
+
if (meta.pivotTable || (prop.kind === core_1.ReferenceKind.EMBEDDED && prop.object)) {
|
|
82
100
|
return true;
|
|
83
101
|
}
|
|
84
102
|
const getRootProperty = (prop) => prop.embedded ? getRootProperty(meta.properties[prop.embedded[0]]) : prop;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Configuration, type Dictionary, type EntityMetadata, type EntityProperty, type NamingStrategy } 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';
|
|
@@ -13,17 +13,23 @@ export declare class DatabaseTable {
|
|
|
13
13
|
private indexes;
|
|
14
14
|
private checks;
|
|
15
15
|
private foreignKeys;
|
|
16
|
+
nativeEnums: Dictionary<unknown[]>;
|
|
16
17
|
comment?: string;
|
|
17
18
|
constructor(platform: AbstractSqlPlatform, name: string, schema?: string | undefined);
|
|
18
19
|
getColumns(): Column[];
|
|
19
20
|
getColumn(name: string): Column | undefined;
|
|
21
|
+
removeColumn(name: string): void;
|
|
20
22
|
getIndexes(): IndexDef[];
|
|
21
23
|
getChecks(): CheckDef[];
|
|
22
24
|
init(cols: Column[], indexes: IndexDef[] | undefined, checks: CheckDef<unknown>[] | undefined, pks: string[], fks?: Dictionary<ForeignKey>, enums?: Dictionary<string[]>): void;
|
|
23
25
|
addColumn(column: Column): void;
|
|
24
|
-
addColumnFromProperty(prop: EntityProperty, meta: EntityMetadata): void;
|
|
26
|
+
addColumnFromProperty(prop: EntityProperty, meta: EntityMetadata, config: Configuration): void;
|
|
25
27
|
private getIndexName;
|
|
26
|
-
getEntityDeclaration(namingStrategy: NamingStrategy, schemaHelper: SchemaHelper): EntityMetadata;
|
|
28
|
+
getEntityDeclaration(namingStrategy: NamingStrategy, schemaHelper: SchemaHelper, scalarPropertiesForRelations: 'always' | 'never' | 'smart'): EntityMetadata;
|
|
29
|
+
private foreignKeysToProps;
|
|
30
|
+
private findFkIndex;
|
|
31
|
+
private getIndexProperties;
|
|
32
|
+
private getSafeBaseNameForFkProp;
|
|
27
33
|
/**
|
|
28
34
|
* The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.
|
|
29
35
|
*/
|
|
@@ -36,10 +42,12 @@ export declare class DatabaseTable {
|
|
|
36
42
|
hasCheck(checkName: string): boolean;
|
|
37
43
|
getPrimaryKey(): IndexDef | undefined;
|
|
38
44
|
hasPrimaryKey(): boolean;
|
|
45
|
+
private getForeignKeyDeclaration;
|
|
39
46
|
private getPropertyDeclaration;
|
|
40
47
|
private getReferenceKind;
|
|
41
48
|
private getPropertyName;
|
|
42
|
-
private
|
|
49
|
+
private getPropertyTypeForForeignKey;
|
|
50
|
+
private getPropertyTypeForColumn;
|
|
43
51
|
private getPropertyDefaultValue;
|
|
44
52
|
addIndex(meta: EntityMetadata, index: {
|
|
45
53
|
properties: string | string[];
|