@mikro-orm/knex 7.0.0-dev.0 → 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 +25 -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 +10 -6
- package/dialects/mysql/MySqlPlatform.js +30 -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 +6 -15
- 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,16 +81,19 @@ 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);
|
|
91
88
|
}
|
|
89
|
+
if (options.readOnly) {
|
|
90
|
+
trxBuilder = trxBuilder.setAccessMode('read only');
|
|
91
|
+
}
|
|
92
92
|
const trx = await trxBuilder.execute();
|
|
93
93
|
for (const query of this.platform.getBeginTransactionSQL(options)) {
|
|
94
94
|
this.logQuery(query);
|
|
95
95
|
}
|
|
96
|
-
await options.eventBroadcaster?.dispatchEvent(
|
|
96
|
+
await options.eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, trx);
|
|
97
97
|
return trx;
|
|
98
98
|
}
|
|
99
99
|
async commit(ctx, eventBroadcaster) {
|
|
@@ -105,10 +105,10 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
105
105
|
this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
|
-
await eventBroadcaster?.dispatchEvent(
|
|
108
|
+
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionCommit, ctx);
|
|
109
109
|
await ctx.commit().execute();
|
|
110
110
|
this.logQuery(this.platform.getCommitTransactionSQL());
|
|
111
|
-
await eventBroadcaster?.dispatchEvent(
|
|
111
|
+
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionCommit, ctx);
|
|
112
112
|
}
|
|
113
113
|
async rollback(ctx, eventBroadcaster) {
|
|
114
114
|
if ('savepointName' in ctx) {
|
|
@@ -116,17 +116,17 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
116
116
|
this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName));
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
await eventBroadcaster?.dispatchEvent(
|
|
119
|
+
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
|
|
120
120
|
await ctx.rollback().execute();
|
|
121
121
|
this.logQuery(this.platform.getRollbackTransactionSQL());
|
|
122
|
-
await eventBroadcaster?.dispatchEvent(
|
|
122
|
+
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
|
|
123
123
|
}
|
|
124
124
|
async execute(query, params = [], method = 'all', ctx, loggerContext) {
|
|
125
125
|
await this.ensureConnection();
|
|
126
|
-
if (query instanceof
|
|
126
|
+
if (query instanceof NativeQueryBuilder) {
|
|
127
127
|
query = query.toRaw();
|
|
128
128
|
}
|
|
129
|
-
if (query instanceof
|
|
129
|
+
if (query instanceof RawQueryFragment) {
|
|
130
130
|
params = query.params;
|
|
131
131
|
query = query.sql;
|
|
132
132
|
}
|
|
@@ -134,7 +134,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
134
134
|
const formatted = this.platform.formatQuery(query, params);
|
|
135
135
|
const sql = this.getSql(query, formatted, loggerContext);
|
|
136
136
|
return this.executeQuery(sql, async () => {
|
|
137
|
-
const compiled =
|
|
137
|
+
const compiled = CompiledQuery.raw(formatted);
|
|
138
138
|
if (ctx) {
|
|
139
139
|
const res = await ctx.executeQuery(compiled);
|
|
140
140
|
return this.transformRawResult(res, method);
|
|
@@ -147,13 +147,14 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
147
147
|
* Execute raw SQL queries from file
|
|
148
148
|
*/
|
|
149
149
|
async loadFile(path) {
|
|
150
|
-
|
|
150
|
+
await this.ensureConnection();
|
|
151
|
+
const buf = await readFile(path);
|
|
151
152
|
try {
|
|
152
|
-
const raw =
|
|
153
|
+
const raw = CompiledQuery.raw(buf.toString());
|
|
153
154
|
await this.client.executeQuery(raw);
|
|
154
155
|
}
|
|
155
156
|
catch (e) {
|
|
156
|
-
/*
|
|
157
|
+
/* v8 ignore next */
|
|
157
158
|
throw this.platform.getExceptionConverter().convertException(e);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
@@ -182,4 +183,3 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
182
183
|
};
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
|
-
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;
|