@mikro-orm/knex 7.0.0-dev.1 → 7.0.0-dev.2
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 +22 -25
- package/AbstractSqlDriver.d.ts +9 -7
- package/AbstractSqlDriver.js +175 -180
- 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 +21 -25
- 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 +1 -1
- package/dialects/sqlite/BaseSqliteConnection.js +7 -11
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +4 -4
- package/dialects/sqlite/BaseSqlitePlatform.js +11 -15
- 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 +5 -14
- package/query/ArrayCriteriaNode.d.ts +2 -2
- package/query/ArrayCriteriaNode.js +2 -6
- package/query/CriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +26 -30
- 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 +37 -41
- package/query/QueryBuilder.d.ts +7 -7
- package/query/QueryBuilder.js +172 -176
- package/query/QueryBuilderHelper.d.ts +4 -4
- package/query/QueryBuilderHelper.js +84 -88
- 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 +26 -30
- 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 +18 -21
- package/schema/index.d.ts +5 -5
- package/schema/index.js +5 -21
- package/typings.d.ts +5 -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) {
|
|
@@ -84,7 +81,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
84
81
|
this.logQuery(this.platform.getSavepointSQL(savepointName));
|
|
85
82
|
return trx;
|
|
86
83
|
}
|
|
87
|
-
await options.eventBroadcaster?.dispatchEvent(
|
|
84
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart);
|
|
88
85
|
let trxBuilder = this.client.startTransaction();
|
|
89
86
|
if (options.isolationLevel) {
|
|
90
87
|
trxBuilder = trxBuilder.setIsolationLevel(options.isolationLevel);
|
|
@@ -96,7 +93,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
96
93
|
for (const query of this.platform.getBeginTransactionSQL(options)) {
|
|
97
94
|
this.logQuery(query);
|
|
98
95
|
}
|
|
99
|
-
await options.eventBroadcaster?.dispatchEvent(
|
|
96
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
|
|
100
97
|
return trx;
|
|
101
98
|
}
|
|
102
99
|
async commit(ctx, eventBroadcaster) {
|
|
@@ -108,10 +105,10 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
108
105
|
this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
|
|
109
106
|
return;
|
|
110
107
|
}
|
|
111
|
-
await eventBroadcaster?.dispatchEvent(
|
|
108
|
+
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionCommit, ctx);
|
|
112
109
|
await ctx.commit().execute();
|
|
113
110
|
this.logQuery(this.platform.getCommitTransactionSQL());
|
|
114
|
-
await eventBroadcaster?.dispatchEvent(
|
|
111
|
+
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionCommit, ctx);
|
|
115
112
|
}
|
|
116
113
|
async rollback(ctx, eventBroadcaster) {
|
|
117
114
|
if ('savepointName' in ctx) {
|
|
@@ -119,17 +116,17 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
119
116
|
this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName));
|
|
120
117
|
return;
|
|
121
118
|
}
|
|
122
|
-
await eventBroadcaster?.dispatchEvent(
|
|
119
|
+
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
|
|
123
120
|
await ctx.rollback().execute();
|
|
124
121
|
this.logQuery(this.platform.getRollbackTransactionSQL());
|
|
125
|
-
await eventBroadcaster?.dispatchEvent(
|
|
122
|
+
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
|
|
126
123
|
}
|
|
127
124
|
async execute(query, params = [], method = 'all', ctx, loggerContext) {
|
|
128
125
|
await this.ensureConnection();
|
|
129
|
-
if (query instanceof
|
|
126
|
+
if (query instanceof NativeQueryBuilder) {
|
|
130
127
|
query = query.toRaw();
|
|
131
128
|
}
|
|
132
|
-
if (query instanceof
|
|
129
|
+
if (query instanceof RawQueryFragment) {
|
|
133
130
|
params = query.params;
|
|
134
131
|
query = query.sql;
|
|
135
132
|
}
|
|
@@ -137,7 +134,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
137
134
|
const formatted = this.platform.formatQuery(query, params);
|
|
138
135
|
const sql = this.getSql(query, formatted, loggerContext);
|
|
139
136
|
return this.executeQuery(sql, async () => {
|
|
140
|
-
const compiled =
|
|
137
|
+
const compiled = CompiledQuery.raw(formatted);
|
|
141
138
|
if (ctx) {
|
|
142
139
|
const res = await ctx.executeQuery(compiled);
|
|
143
140
|
return this.transformRawResult(res, method);
|
|
@@ -150,13 +147,14 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
150
147
|
* Execute raw SQL queries from file
|
|
151
148
|
*/
|
|
152
149
|
async loadFile(path) {
|
|
153
|
-
|
|
150
|
+
await this.ensureConnection();
|
|
151
|
+
const buf = await readFile(path);
|
|
154
152
|
try {
|
|
155
|
-
const raw =
|
|
153
|
+
const raw = CompiledQuery.raw(buf.toString());
|
|
156
154
|
await this.client.executeQuery(raw);
|
|
157
155
|
}
|
|
158
156
|
catch (e) {
|
|
159
|
-
/*
|
|
157
|
+
/* v8 ignore next */
|
|
160
158
|
throw this.platform.getExceptionConverter().convertException(e);
|
|
161
159
|
}
|
|
162
160
|
}
|
|
@@ -185,4 +183,3 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
185
183
|
};
|
|
186
184
|
}
|
|
187
185
|
}
|
|
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,7 +13,7 @@ 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
|
|
16
|
+
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
15
17
|
find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
|
|
16
18
|
findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<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;
|