@mikro-orm/sql 7.0.0-rc.2 → 7.0.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.
- package/AbstractSqlConnection.d.ts +5 -4
- package/AbstractSqlConnection.js +20 -6
- package/AbstractSqlDriver.d.ts +19 -13
- package/AbstractSqlDriver.js +225 -47
- package/AbstractSqlPlatform.d.ts +35 -0
- package/AbstractSqlPlatform.js +51 -5
- package/PivotCollectionPersister.d.ts +2 -11
- package/PivotCollectionPersister.js +59 -59
- package/README.md +5 -4
- package/SqlEntityManager.d.ts +2 -2
- package/SqlEntityManager.js +5 -5
- package/dialects/index.d.ts +1 -0
- package/dialects/index.js +1 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +2 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +8 -4
- package/dialects/mysql/BaseMySqlPlatform.d.ts +6 -0
- package/dialects/mysql/BaseMySqlPlatform.js +18 -2
- package/dialects/mysql/MySqlSchemaHelper.d.ts +1 -1
- package/dialects/mysql/MySqlSchemaHelper.js +25 -14
- package/dialects/oracledb/OracleDialect.d.ts +78 -0
- package/dialects/oracledb/OracleDialect.js +166 -0
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +19 -0
- package/dialects/oracledb/OracleNativeQueryBuilder.js +249 -0
- package/dialects/oracledb/index.d.ts +2 -0
- package/dialects/oracledb/index.js +2 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +6 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.js +49 -37
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +75 -59
- package/dialects/sqlite/BaseSqliteConnection.js +2 -2
- package/dialects/sqlite/NodeSqliteDialect.js +3 -1
- package/dialects/sqlite/SqlitePlatform.d.ts +1 -0
- package/dialects/sqlite/SqlitePlatform.js +7 -1
- package/dialects/sqlite/SqliteSchemaHelper.js +23 -17
- package/index.d.ts +1 -1
- package/index.js +0 -1
- package/package.json +30 -30
- package/plugin/index.d.ts +1 -14
- package/plugin/index.js +13 -13
- package/plugin/transformer.d.ts +6 -22
- package/plugin/transformer.js +91 -82
- package/query/ArrayCriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +28 -10
- package/query/CriteriaNodeFactory.js +20 -4
- package/query/NativeQueryBuilder.d.ts +28 -3
- package/query/NativeQueryBuilder.js +65 -3
- package/query/ObjectCriteriaNode.js +75 -31
- package/query/QueryBuilder.d.ts +199 -100
- package/query/QueryBuilder.js +544 -358
- package/query/QueryBuilderHelper.d.ts +18 -14
- package/query/QueryBuilderHelper.js +364 -147
- package/query/ScalarCriteriaNode.js +17 -8
- package/query/enums.d.ts +2 -0
- package/query/enums.js +2 -0
- package/query/raw.js +1 -1
- package/schema/DatabaseSchema.d.ts +7 -5
- package/schema/DatabaseSchema.js +68 -45
- package/schema/DatabaseTable.d.ts +8 -6
- package/schema/DatabaseTable.js +191 -107
- package/schema/SchemaComparator.d.ts +1 -3
- package/schema/SchemaComparator.js +76 -50
- package/schema/SchemaHelper.d.ts +2 -13
- package/schema/SchemaHelper.js +30 -9
- package/schema/SqlSchemaGenerator.d.ts +4 -14
- package/schema/SqlSchemaGenerator.js +26 -12
- package/typings.d.ts +10 -5
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { type ControlledTransaction, type Dialect, Kysely } from 'kysely';
|
|
2
|
-
import { type AnyEntity, Connection, type Dictionary, type EntityData, type IsolationLevel, type LogContext, type LoggingOptions, type QueryResult, RawQueryFragment, type Transaction, type TransactionEventBroadcaster } from '@mikro-orm/core';
|
|
2
|
+
import { type AnyEntity, Connection, type Dictionary, type EntityData, type IsolationLevel, type LogContext, type LoggingOptions, type MaybePromise, type QueryResult, RawQueryFragment, type Transaction, type TransactionEventBroadcaster } from '@mikro-orm/core';
|
|
3
3
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js';
|
|
4
4
|
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
5
5
|
export declare abstract class AbstractSqlConnection extends Connection {
|
|
6
6
|
#private;
|
|
7
7
|
protected platform: AbstractSqlPlatform;
|
|
8
|
-
abstract createKyselyDialect(overrides: Dictionary): Dialect
|
|
8
|
+
abstract createKyselyDialect(overrides: Dictionary): MaybePromise<Dialect>;
|
|
9
9
|
connect(options?: {
|
|
10
10
|
skipOnConnect?: boolean;
|
|
11
11
|
}): Promise<void>;
|
|
12
|
-
createKysely(): void
|
|
12
|
+
createKysely(): MaybePromise<void>;
|
|
13
13
|
/**
|
|
14
14
|
* @inheritDoc
|
|
15
15
|
*/
|
|
@@ -29,6 +29,7 @@ export declare abstract class AbstractSqlConnection extends Connection {
|
|
|
29
29
|
error?: Error;
|
|
30
30
|
}>;
|
|
31
31
|
getClient<T = any>(): Kysely<T>;
|
|
32
|
+
initClient(): Promise<void>;
|
|
32
33
|
transactional<T>(cb: (trx: Transaction<ControlledTransaction<any, any>>) => Promise<T>, options?: {
|
|
33
34
|
isolationLevel?: IsolationLevel;
|
|
34
35
|
readOnly?: boolean;
|
|
@@ -50,6 +51,6 @@ export declare abstract class AbstractSqlConnection extends Connection {
|
|
|
50
51
|
stream<T extends EntityData<AnyEntity>>(query: string | NativeQueryBuilder | RawQueryFragment, params?: readonly unknown[], ctx?: Transaction<Kysely<any>>, loggerContext?: LoggingOptions): AsyncIterableIterator<T>;
|
|
51
52
|
/** @inheritDoc */
|
|
52
53
|
executeDump(dump: string): Promise<void>;
|
|
53
|
-
|
|
54
|
+
protected getSql(query: string, formatted: string, context?: LogContext): string;
|
|
54
55
|
protected transformRawResult<T>(res: any, method?: 'all' | 'get' | 'run'): T;
|
|
55
56
|
}
|
package/AbstractSqlConnection.js
CHANGED
|
@@ -4,7 +4,7 @@ import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
|
4
4
|
export class AbstractSqlConnection extends Connection {
|
|
5
5
|
#client;
|
|
6
6
|
async connect(options) {
|
|
7
|
-
this.
|
|
7
|
+
await this.initClient();
|
|
8
8
|
this.connected = true;
|
|
9
9
|
if (options?.skipOnConnect !== true) {
|
|
10
10
|
await this.onConnect();
|
|
@@ -24,9 +24,13 @@ export class AbstractSqlConnection extends Connection {
|
|
|
24
24
|
this.#client = new Kysely({ dialect: driverOptions });
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const dialect = this.createKyselyDialect(driverOptions);
|
|
28
|
+
if (dialect instanceof Promise) {
|
|
29
|
+
return dialect.then(d => {
|
|
30
|
+
this.#client = new Kysely({ dialect: d });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
this.#client = new Kysely({ dialect });
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
@@ -62,10 +66,19 @@ export class AbstractSqlConnection extends Connection {
|
|
|
62
66
|
}
|
|
63
67
|
getClient() {
|
|
64
68
|
if (!this.#client) {
|
|
65
|
-
this.createKysely();
|
|
69
|
+
const maybePromise = this.createKysely();
|
|
70
|
+
/* v8 ignore next */
|
|
71
|
+
if (maybePromise instanceof Promise) {
|
|
72
|
+
throw new Error('Current driver requires async initialization, use `MikroORM.init()` instead of the constructor');
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
return this.#client;
|
|
68
76
|
}
|
|
77
|
+
async initClient() {
|
|
78
|
+
if (!this.#client) {
|
|
79
|
+
await this.createKysely();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
69
82
|
async transactional(cb, options = {}) {
|
|
70
83
|
const trx = await this.begin(options);
|
|
71
84
|
try {
|
|
@@ -181,7 +194,8 @@ export class AbstractSqlConnection extends Connection {
|
|
|
181
194
|
try {
|
|
182
195
|
const res = (ctx ?? this.getClient()).getExecutor().stream(compiled, 1);
|
|
183
196
|
this.logQuery(sql, {
|
|
184
|
-
sql,
|
|
197
|
+
sql,
|
|
198
|
+
params,
|
|
185
199
|
...loggerContext,
|
|
186
200
|
affected: Utils.isPlainObject(res) ? res.affectedRows : undefined,
|
|
187
201
|
});
|
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type FormulaTable, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, type Raw, RawQueryFragment, type StreamOptions, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
|
|
2
2
|
import type { AbstractSqlConnection } from './AbstractSqlConnection.js';
|
|
3
3
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js';
|
|
4
|
-
import {
|
|
4
|
+
import { type AnyQueryBuilder } from './query/QueryBuilder.js';
|
|
5
5
|
import { type NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
6
6
|
import { QueryType } from './query/enums.js';
|
|
7
7
|
import { SqlEntityManager } from './SqlEntityManager.js';
|
|
@@ -36,7 +36,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
36
36
|
* Force balanced strategy to load to-many relations via separate queries.
|
|
37
37
|
*/
|
|
38
38
|
private forceBalancedStrategy;
|
|
39
|
-
mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?:
|
|
39
|
+
mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: AnyQueryBuilder<T>, map?: Dictionary): EntityData<T> | null;
|
|
40
40
|
/**
|
|
41
41
|
* Maps aliased columns from TPT parent tables back to their original field names.
|
|
42
42
|
* TPT parent columns are selected with aliases like `parent_alias__column_name`,
|
|
@@ -53,7 +53,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
53
53
|
nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
54
54
|
nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
|
|
55
55
|
nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
|
|
56
|
-
nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T
|
|
56
|
+
nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>, transform?: (sql: string, params: any[]) => string): Promise<QueryResult<T>>;
|
|
57
57
|
nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
|
|
58
58
|
/**
|
|
59
59
|
* Fast comparison for collection snapshots that are represented by PK arrays.
|
|
@@ -99,17 +99,17 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
99
99
|
*/
|
|
100
100
|
mergeJoinedResult<T extends object>(rawResults: EntityData<T>[], meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[]): EntityData<T>[];
|
|
101
101
|
protected shouldHaveColumn<T, U>(meta: EntityMetadata<T>, prop: EntityProperty<U>, populate: readonly PopulateOptions<U>[], fields?: readonly InternalField<U>[], exclude?: readonly InternalField<U>[]): boolean;
|
|
102
|
-
protected getFieldsForJoinedLoad<T extends object>(qb:
|
|
102
|
+
protected getFieldsForJoinedLoad<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, options: FieldsForJoinedLoadOptions<T>): InternalField<T>[];
|
|
103
103
|
/**
|
|
104
104
|
* Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class.
|
|
105
105
|
* @internal
|
|
106
106
|
*/
|
|
107
|
-
protected addTPTPolymorphicJoinsForRelation<T extends object>(qb:
|
|
107
|
+
protected addTPTPolymorphicJoinsForRelation<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, baseAlias: string, fields: InternalField<T>[]): void;
|
|
108
108
|
/**
|
|
109
109
|
* Find the alias for a TPT child table in the query builder.
|
|
110
110
|
* @internal
|
|
111
111
|
*/
|
|
112
|
-
protected findTPTChildAlias<T extends object>(qb:
|
|
112
|
+
protected findTPTChildAlias<T extends object>(qb: AnyQueryBuilder<T>, childMeta: EntityMetadata): string | undefined;
|
|
113
113
|
/**
|
|
114
114
|
* Builds a CASE WHEN expression for TPT discriminator.
|
|
115
115
|
* Determines concrete entity type based on which child table has a non-null PK.
|
|
@@ -122,13 +122,13 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
122
122
|
* This method reads the discriminator to determine the concrete type and maps child-specific fields.
|
|
123
123
|
* @internal
|
|
124
124
|
*/
|
|
125
|
-
protected mapTPTChildFields<T extends object>(relationPojo: EntityData<T>, meta: EntityMetadata<T>, relationAlias: string, qb:
|
|
125
|
+
protected mapTPTChildFields<T extends object>(relationPojo: EntityData<T>, meta: EntityMetadata<T>, relationAlias: string, qb: AnyQueryBuilder<T>, root: EntityData<T>): void;
|
|
126
126
|
/**
|
|
127
127
|
* @internal
|
|
128
128
|
*/
|
|
129
|
-
mapPropToFieldNames<T extends object>(qb:
|
|
129
|
+
mapPropToFieldNames<T extends object>(qb: AnyQueryBuilder<T>, prop: EntityProperty<T>, tableAlias: string, meta: EntityMetadata<T>, schema?: string, explicitFields?: readonly InternalField<T>[]): InternalField<T>[];
|
|
130
130
|
/** @internal */
|
|
131
|
-
createQueryBuilder<T extends object>(entityName: EntityName<T> |
|
|
131
|
+
createQueryBuilder<T extends object>(entityName: EntityName<T> | AnyQueryBuilder<T>, ctx?: Transaction, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): AnyQueryBuilder<T>;
|
|
132
132
|
protected resolveConnectionType(args: {
|
|
133
133
|
ctx?: Transaction;
|
|
134
134
|
connectionType?: ConnectionType;
|
|
@@ -137,13 +137,19 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
137
137
|
protected processManyToMany<T extends object>(meta: EntityMetadata<T>, pks: Primary<T>[], collections: EntityData<T>, clear: boolean, options?: DriverMethodOptions): Promise<void>;
|
|
138
138
|
lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
|
|
139
139
|
protected buildPopulateWhere<T extends object>(meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[], options: Pick<FindOptions<any>, 'populateWhere'>): ObjectQuery<T>;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Builds a UNION ALL (or UNION) subquery from `unionWhere` branches and merges it
|
|
142
|
+
* into the main WHERE as `pk IN (branch_1 UNION ALL branch_2 ...)`.
|
|
143
|
+
* Each branch is planned independently by the database, enabling per-table index usage.
|
|
144
|
+
*/
|
|
145
|
+
protected applyUnionWhere<T extends object>(meta: EntityMetadata<T>, where: ObjectQuery<T>, options: FindOptions<T, any, any, any> | CountOptions<T> | NativeInsertUpdateOptions<T> | DeleteOptions<T>, forDml?: boolean): Promise<ObjectQuery<T>>;
|
|
146
|
+
protected buildOrderBy<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], options: Pick<FindOptions<any>, 'strategy' | 'orderBy' | 'populateOrderBy'>): QueryOrderMap<T>[];
|
|
147
|
+
protected buildPopulateOrderBy<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, populateOrderBy: QueryOrderMap<T>[], parentPath: string, explicit: boolean, parentAlias?: string): QueryOrderMap<T>[];
|
|
148
|
+
protected buildJoinedPropsOrderBy<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], options?: Pick<FindOptions<any>, 'strategy' | 'orderBy' | 'populateOrderBy'>, parentPath?: string): QueryOrderMap<T>[];
|
|
143
149
|
private buildToManyOrderBy;
|
|
144
150
|
protected normalizeFields<T extends object>(fields: InternalField<T>[], prefix?: string): string[];
|
|
145
151
|
protected processField<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T> | undefined, field: string, ret: InternalField<T>[]): void;
|
|
146
|
-
protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb:
|
|
152
|
+
protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: AnyQueryBuilder<T>, alias: string, options: Pick<FindOptions<T, any, any, any>, 'strategy' | 'fields' | 'exclude'>, schema?: string): InternalField<T>[];
|
|
147
153
|
}
|
|
148
154
|
interface FieldsForJoinedLoadOptions<T extends object> {
|
|
149
155
|
explicitFields?: readonly InternalField<T>[];
|