@mikro-orm/knex 7.0.0-dev.1 → 7.0.0-dev.10
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 +2 -2
- package/AbstractSqlConnection.js +33 -31
- package/AbstractSqlDriver.d.ts +14 -12
- package/AbstractSqlDriver.js +198 -186
- package/AbstractSqlPlatform.d.ts +4 -4
- package/AbstractSqlPlatform.js +17 -21
- package/PivotCollectionPersister.d.ts +1 -1
- package/PivotCollectionPersister.js +5 -8
- package/SqlEntityManager.d.ts +4 -3
- package/SqlEntityManager.js +2 -6
- package/SqlEntityRepository.d.ts +2 -2
- package/SqlEntityRepository.js +2 -6
- package/dialects/index.d.ts +4 -4
- package/dialects/index.js +4 -20
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +29 -29
- package/dialects/mssql/index.d.ts +1 -1
- package/dialects/mssql/index.js +1 -17
- package/dialects/mysql/MySqlExceptionConverter.js +16 -19
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/mysql/MySqlNativeQueryBuilder.js +13 -17
- package/dialects/mysql/MySqlPlatform.d.ts +5 -5
- package/dialects/mysql/MySqlPlatform.js +16 -20
- package/dialects/mysql/MySqlSchemaHelper.d.ts +5 -5
- package/dialects/mysql/MySqlSchemaHelper.js +8 -12
- package/dialects/mysql/index.d.ts +4 -4
- package/dialects/mysql/index.js +4 -20
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +2 -6
- package/dialects/postgresql/index.d.ts +1 -1
- package/dialects/postgresql/index.js +1 -17
- package/dialects/sqlite/BaseSqliteConnection.d.ts +2 -2
- package/dialects/sqlite/BaseSqliteConnection.js +14 -12
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +4 -5
- package/dialects/sqlite/BaseSqlitePlatform.js +11 -19
- package/dialects/sqlite/SqliteExceptionConverter.js +16 -19
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +1 -1
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +2 -6
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +5 -5
- package/dialects/sqlite/SqliteSchemaHelper.js +22 -26
- package/dialects/sqlite/index.d.ts +5 -5
- package/dialects/sqlite/index.js +5 -21
- package/index.d.ts +11 -11
- package/index.js +13 -34
- package/package.json +7 -16
- package/query/ArrayCriteriaNode.d.ts +2 -2
- package/query/ArrayCriteriaNode.js +2 -6
- package/query/CriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +25 -33
- package/query/CriteriaNodeFactory.d.ts +1 -1
- package/query/CriteriaNodeFactory.js +17 -21
- package/query/NativeQueryBuilder.d.ts +2 -2
- package/query/NativeQueryBuilder.js +33 -37
- package/query/ObjectCriteriaNode.d.ts +2 -2
- package/query/ObjectCriteriaNode.js +43 -43
- package/query/QueryBuilder.d.ts +17 -15
- package/query/QueryBuilder.js +204 -193
- package/query/QueryBuilderHelper.d.ts +4 -4
- package/query/QueryBuilderHelper.js +86 -96
- package/query/ScalarCriteriaNode.d.ts +2 -2
- package/query/ScalarCriteriaNode.js +12 -16
- package/query/enums.js +4 -7
- package/query/index.d.ts +9 -9
- package/query/index.js +9 -25
- package/schema/DatabaseSchema.d.ts +3 -3
- package/schema/DatabaseSchema.js +7 -11
- package/schema/DatabaseTable.d.ts +3 -3
- package/schema/DatabaseTable.js +44 -33
- package/schema/SchemaComparator.d.ts +4 -4
- package/schema/SchemaComparator.js +15 -19
- package/schema/SchemaHelper.d.ts +5 -5
- package/schema/SchemaHelper.js +22 -26
- package/schema/SqlSchemaGenerator.d.ts +4 -4
- package/schema/SqlSchemaGenerator.js +23 -36
- package/schema/index.d.ts +5 -5
- package/schema/index.js +5 -21
- package/typings.d.ts +7 -4
- package/typings.js +1 -2
- package/index.mjs +0 -232
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ControlledTransaction, type Dialect, Kysely } from 'kysely';
|
|
2
2
|
import { type AnyEntity, Connection, type Dictionary, type EntityData, type IsolationLevel, type LoggingOptions, type QueryResult, RawQueryFragment, type Transaction, type TransactionEventBroadcaster } from '@mikro-orm/core';
|
|
3
|
-
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
4
|
-
import { NativeQueryBuilder } from './query';
|
|
3
|
+
import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js';
|
|
4
|
+
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
5
5
|
export declare abstract class AbstractSqlConnection extends Connection {
|
|
6
6
|
protected platform: AbstractSqlPlatform;
|
|
7
7
|
protected client: Kysely<any>;
|
package/AbstractSqlConnection.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const core_1 = require("@mikro-orm/core");
|
|
7
|
-
const query_1 = require("./query");
|
|
8
|
-
class AbstractSqlConnection extends core_1.Connection {
|
|
1
|
+
import { CompiledQuery, Kysely, } from 'kysely';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { Connection, EventType, RawQueryFragment, } from '@mikro-orm/core';
|
|
4
|
+
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
5
|
+
export class AbstractSqlConnection extends Connection {
|
|
9
6
|
client;
|
|
10
7
|
async connect() {
|
|
11
8
|
let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');
|
|
12
9
|
if (typeof driverOptions === 'function') {
|
|
13
10
|
driverOptions = await driverOptions();
|
|
14
11
|
}
|
|
15
|
-
if (driverOptions instanceof
|
|
12
|
+
if (driverOptions instanceof Kysely) {
|
|
16
13
|
this.logger.log('info', 'Reusing Kysely client provided via `driverOptions`');
|
|
17
14
|
this.client = driverOptions;
|
|
18
15
|
}
|
|
19
16
|
else if ('createDriver' in driverOptions) {
|
|
20
17
|
this.logger.log('info', 'Reusing Kysely dialect provided via `driverOptions`');
|
|
21
|
-
this.client = new
|
|
18
|
+
this.client = new Kysely({ dialect: driverOptions });
|
|
22
19
|
}
|
|
23
20
|
else {
|
|
24
|
-
this.client = new
|
|
21
|
+
this.client = new Kysely({
|
|
25
22
|
dialect: this.createKyselyDialect(driverOptions),
|
|
26
23
|
// log: m => console.log(m),
|
|
27
24
|
});
|
|
@@ -51,7 +48,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
51
48
|
return { ok: false, reason: 'Connection not established' };
|
|
52
49
|
}
|
|
53
50
|
try {
|
|
54
|
-
await this.client.executeQuery(
|
|
51
|
+
await this.client.executeQuery(CompiledQuery.raw('select 1'));
|
|
55
52
|
return { ok: true };
|
|
56
53
|
}
|
|
57
54
|
catch (error) {
|
|
@@ -76,15 +73,18 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
76
73
|
async begin(options = {}) {
|
|
77
74
|
if (options.ctx) {
|
|
78
75
|
const ctx = options.ctx;
|
|
76
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart, ctx);
|
|
79
77
|
ctx.index ??= 0;
|
|
80
78
|
const savepointName = `trx${ctx.index + 1}`;
|
|
81
79
|
const trx = await options.ctx.savepoint(savepointName).execute();
|
|
82
80
|
Reflect.defineProperty(trx, 'index', { value: ctx.index + 1 });
|
|
83
81
|
Reflect.defineProperty(trx, 'savepointName', { value: savepointName });
|
|
84
82
|
this.logQuery(this.platform.getSavepointSQL(savepointName));
|
|
83
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
|
|
85
84
|
return trx;
|
|
86
85
|
}
|
|
87
|
-
await
|
|
86
|
+
await this.ensureConnection();
|
|
87
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart);
|
|
88
88
|
let trxBuilder = this.client.startTransaction();
|
|
89
89
|
if (options.isolationLevel) {
|
|
90
90
|
trxBuilder = trxBuilder.setIsolationLevel(options.isolationLevel);
|
|
@@ -96,40 +96,42 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
96
96
|
for (const query of this.platform.getBeginTransactionSQL(options)) {
|
|
97
97
|
this.logQuery(query);
|
|
98
98
|
}
|
|
99
|
-
await options.eventBroadcaster?.dispatchEvent(
|
|
99
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
|
|
100
100
|
return trx;
|
|
101
101
|
}
|
|
102
102
|
async commit(ctx, eventBroadcaster) {
|
|
103
103
|
if (ctx.isRolledBack) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
+
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionCommit, ctx);
|
|
106
107
|
if ('savepointName' in ctx) {
|
|
107
108
|
await ctx.releaseSavepoint(ctx.savepointName).execute();
|
|
108
109
|
this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
|
|
109
|
-
return;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
else {
|
|
112
|
+
await ctx.commit().execute();
|
|
113
|
+
this.logQuery(this.platform.getCommitTransactionSQL());
|
|
114
|
+
}
|
|
115
|
+
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionCommit, ctx);
|
|
115
116
|
}
|
|
116
117
|
async rollback(ctx, eventBroadcaster) {
|
|
118
|
+
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
|
|
117
119
|
if ('savepointName' in ctx) {
|
|
118
120
|
await ctx.rollbackToSavepoint(ctx.savepointName).execute();
|
|
119
121
|
this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName));
|
|
120
|
-
return;
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
else {
|
|
124
|
+
await ctx.rollback().execute();
|
|
125
|
+
this.logQuery(this.platform.getRollbackTransactionSQL());
|
|
126
|
+
}
|
|
127
|
+
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
|
|
126
128
|
}
|
|
127
129
|
async execute(query, params = [], method = 'all', ctx, loggerContext) {
|
|
128
130
|
await this.ensureConnection();
|
|
129
|
-
if (query instanceof
|
|
131
|
+
if (query instanceof NativeQueryBuilder) {
|
|
130
132
|
query = query.toRaw();
|
|
131
133
|
}
|
|
132
|
-
if (query instanceof
|
|
134
|
+
if (query instanceof RawQueryFragment) {
|
|
133
135
|
params = query.params;
|
|
134
136
|
query = query.sql;
|
|
135
137
|
}
|
|
@@ -137,7 +139,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
137
139
|
const formatted = this.platform.formatQuery(query, params);
|
|
138
140
|
const sql = this.getSql(query, formatted, loggerContext);
|
|
139
141
|
return this.executeQuery(sql, async () => {
|
|
140
|
-
const compiled =
|
|
142
|
+
const compiled = CompiledQuery.raw(formatted);
|
|
141
143
|
if (ctx) {
|
|
142
144
|
const res = await ctx.executeQuery(compiled);
|
|
143
145
|
return this.transformRawResult(res, method);
|
|
@@ -150,13 +152,14 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
150
152
|
* Execute raw SQL queries from file
|
|
151
153
|
*/
|
|
152
154
|
async loadFile(path) {
|
|
153
|
-
|
|
155
|
+
await this.ensureConnection();
|
|
156
|
+
const buf = await readFile(path);
|
|
154
157
|
try {
|
|
155
|
-
const raw =
|
|
158
|
+
const raw = CompiledQuery.raw(buf.toString());
|
|
156
159
|
await this.client.executeQuery(raw);
|
|
157
160
|
}
|
|
158
161
|
catch (e) {
|
|
159
|
-
/*
|
|
162
|
+
/* v8 ignore next */
|
|
160
163
|
throw this.platform.getExceptionConverter().convertException(e);
|
|
161
164
|
}
|
|
162
165
|
}
|
|
@@ -185,4 +188,3 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
185
188
|
};
|
|
186
189
|
}
|
|
187
190
|
}
|
|
188
|
-
exports.AbstractSqlConnection = AbstractSqlConnection;
|
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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
|
|
2
|
-
import type { AbstractSqlConnection } from './AbstractSqlConnection';
|
|
3
|
-
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
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 LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, RawQueryFragment, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
|
|
2
|
+
import type { AbstractSqlConnection } from './AbstractSqlConnection.js';
|
|
3
|
+
import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js';
|
|
4
|
+
import { QueryBuilder } from './query/QueryBuilder.js';
|
|
5
|
+
import { type NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
6
|
+
import { QueryType } from './query/enums.js';
|
|
7
|
+
import { SqlEntityManager } from './SqlEntityManager.js';
|
|
8
|
+
import type { Field } from './typings.js';
|
|
7
9
|
export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlConnection = AbstractSqlConnection, Platform extends AbstractSqlPlatform = AbstractSqlPlatform> extends DatabaseDriver<Connection> {
|
|
8
10
|
[EntityManagerType]: SqlEntityManager<this>;
|
|
9
11
|
protected readonly connection: Connection;
|
|
@@ -11,13 +13,13 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
11
13
|
protected readonly platform: Platform;
|
|
12
14
|
protected constructor(config: Configuration, platform: Platform, connection: Constructor<Connection>, connector: string[]);
|
|
13
15
|
getPlatform(): Platform;
|
|
14
|
-
createEntityManager
|
|
15
|
-
find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where:
|
|
16
|
-
findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where:
|
|
16
|
+
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
17
|
+
find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: ObjectQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
|
|
18
|
+
findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: ObjectQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
|
|
17
19
|
protected hasToManyJoins<T extends object>(hint: PopulateOptions<T>, meta: EntityMetadata<T>): boolean;
|
|
18
|
-
findVirtual<T extends object>(entityName: string, where:
|
|
19
|
-
countVirtual<T extends object>(entityName: string, where:
|
|
20
|
-
protected findFromVirtual<T extends object>(entityName: string, where:
|
|
20
|
+
findVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
|
|
21
|
+
countVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: CountOptions<T, any>): Promise<number>;
|
|
22
|
+
protected findFromVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: FindOptions<T, any> | CountOptions<T, any>, type: QueryType): Promise<EntityData<T>[] | number>;
|
|
21
23
|
protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType): Promise<T[] | number>;
|
|
22
24
|
mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: QueryBuilder<T, any, any, any>, map?: Dictionary): EntityData<T> | null;
|
|
23
25
|
private mapJoinedProps;
|