@mikro-orm/knex 6.0.0-dev.67 → 6.0.0-dev.69
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { AnyEntity, Configuration, ConnectionOptions, EntityData, IsolationLevel,
|
|
2
|
+
import type { AnyEntity, Configuration, ConnectionOptions, EntityData, IsolationLevel, LoggingOptions, QueryResult, Transaction, TransactionEventBroadcaster } from '@mikro-orm/core';
|
|
3
3
|
import { Connection } from '@mikro-orm/core';
|
|
4
4
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
5
5
|
export declare abstract class AbstractSqlConnection extends Connection {
|
|
@@ -25,7 +25,7 @@ export declare abstract class AbstractSqlConnection extends Connection {
|
|
|
25
25
|
}): Promise<Knex.Transaction>;
|
|
26
26
|
commit(ctx: Knex.Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
27
27
|
rollback(ctx: Knex.Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
28
|
-
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(queryOrKnex: string | Knex.QueryBuilder | Knex.Raw, params?: unknown[], method?: 'all' | 'get' | 'run', ctx?: Transaction,
|
|
28
|
+
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(queryOrKnex: string | Knex.QueryBuilder | Knex.Raw, params?: unknown[], method?: 'all' | 'get' | 'run', ctx?: Transaction, logging?: LoggingOptions): Promise<T>;
|
|
29
29
|
/**
|
|
30
30
|
* Execute raw SQL queries from file
|
|
31
31
|
*/
|
package/AbstractSqlConnection.js
CHANGED
|
@@ -83,7 +83,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
83
83
|
await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionRollback, ctx);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
async execute(queryOrKnex, params = [], method = 'all', ctx,
|
|
86
|
+
async execute(queryOrKnex, params = [], method = 'all', ctx, logging) {
|
|
87
87
|
await this.ensureConnection();
|
|
88
88
|
if (core_1.Utils.isObject(queryOrKnex)) {
|
|
89
89
|
ctx ??= (queryOrKnex.client.transacting ? queryOrKnex : null);
|
|
@@ -92,14 +92,14 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
92
92
|
params = q.bindings;
|
|
93
93
|
}
|
|
94
94
|
const formatted = this.platform.formatQuery(queryOrKnex, params);
|
|
95
|
-
const sql = this.getSql(queryOrKnex, formatted);
|
|
95
|
+
const sql = this.getSql(queryOrKnex, formatted, logging);
|
|
96
96
|
const res = await this.executeQuery(sql, () => {
|
|
97
97
|
const query = this.getKnex().raw(formatted);
|
|
98
98
|
if (ctx) {
|
|
99
99
|
query.transacting(ctx);
|
|
100
100
|
}
|
|
101
101
|
return query;
|
|
102
|
-
}, { query: queryOrKnex, params, ...
|
|
102
|
+
}, { query: queryOrKnex, params, ...logging });
|
|
103
103
|
return this.transformRawResult(res, method);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -146,12 +146,12 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
146
146
|
};
|
|
147
147
|
return config;
|
|
148
148
|
}
|
|
149
|
-
getSql(query, formatted) {
|
|
149
|
+
getSql(query, formatted, context) {
|
|
150
150
|
const logger = this.config.getLogger();
|
|
151
|
-
if (!logger.isEnabled('query')) {
|
|
151
|
+
if (!logger.isEnabled('query', context)) {
|
|
152
152
|
return query;
|
|
153
153
|
}
|
|
154
|
-
if (logger.isEnabled('query-params')) {
|
|
154
|
+
if (logger.isEnabled('query-params', context)) {
|
|
155
155
|
return formatted;
|
|
156
156
|
}
|
|
157
157
|
return this.getKnex().client.positionBindings(query);
|
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { AnyEntity, Collection, ConnectionType, Configuration, Constructor, CountOptions, DeleteOptions, Dictionary, DriverMethodOptions, EntityData, EntityDictionary, EntityField, EntityMetadata, EntityName, EntityProperty, FilterQuery, FindOneOptions, FindOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateManyOptions, NativeInsertUpdateOptions, PopulateOptions, Primary, QueryOrderMap, QueryResult, Transaction, OrderDefinition,
|
|
2
|
+
import type { AnyEntity, Collection, ConnectionType, Configuration, Constructor, CountOptions, DeleteOptions, Dictionary, DriverMethodOptions, EntityData, EntityDictionary, EntityField, EntityMetadata, EntityName, EntityProperty, FilterQuery, FindOneOptions, FindOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateManyOptions, NativeInsertUpdateOptions, PopulateOptions, Primary, QueryOrderMap, QueryResult, Transaction, OrderDefinition, LoggingOptions } from '@mikro-orm/core';
|
|
3
3
|
import { DatabaseDriver, EntityManagerType } from '@mikro-orm/core';
|
|
4
4
|
import type { AbstractSqlConnection } from './AbstractSqlConnection';
|
|
5
5
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
@@ -48,7 +48,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
48
48
|
*/
|
|
49
49
|
mapPropToFieldNames<T extends object>(qb: QueryBuilder<T>, prop: EntityProperty<T>, tableAlias?: string): Field<T>[];
|
|
50
50
|
/** @internal */
|
|
51
|
-
createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean,
|
|
51
|
+
createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, logging?: LoggingOptions): QueryBuilder<T>;
|
|
52
52
|
protected resolveConnectionType(args: {
|
|
53
53
|
ctx?: Transaction<Knex.Transaction>;
|
|
54
54
|
connectionType?: ConnectionType;
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -26,7 +26,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
26
26
|
}
|
|
27
27
|
const populate = this.autoJoinOneToOneOwner(meta, options.populate, options.fields);
|
|
28
28
|
const joinedProps = this.joinedProps(meta, populate);
|
|
29
|
-
const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.
|
|
29
|
+
const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.logging);
|
|
30
30
|
const fields = this.buildFields(meta, populate, joinedProps, qb, options.fields);
|
|
31
31
|
const joinedPropsOrderBy = this.buildJoinedPropsOrderBy(entityName, qb, meta, joinedProps);
|
|
32
32
|
const orderBy = [...core_1.Utils.asArray(options.orderBy), ...joinedPropsOrderBy];
|
|
@@ -650,9 +650,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
650
650
|
return prop.fieldNames;
|
|
651
651
|
}
|
|
652
652
|
/** @internal */
|
|
653
|
-
createQueryBuilder(entityName, ctx, preferredConnectionType, convertCustomTypes,
|
|
653
|
+
createQueryBuilder(entityName, ctx, preferredConnectionType, convertCustomTypes, logging) {
|
|
654
654
|
const connectionType = this.resolveConnectionType({ ctx, connectionType: preferredConnectionType });
|
|
655
|
-
const qb = new query_1.QueryBuilder(entityName, this.metadata, this, ctx, undefined, connectionType, undefined,
|
|
655
|
+
const qb = new query_1.QueryBuilder(entityName, this.metadata, this, ctx, undefined, connectionType, undefined, logging);
|
|
656
656
|
if (!convertCustomTypes) {
|
|
657
657
|
qb.unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES);
|
|
658
658
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.69",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^5.7.2"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
69
|
+
"@mikro-orm/core": "~6.0.0-dev.69"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { inspect } from 'util';
|
|
3
3
|
import type { Knex } from 'knex';
|
|
4
|
-
import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator,
|
|
4
|
+
import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator, LoggingOptions, MetadataStorage, ObjectQuery, PopulateOptions, QBFilterQuery, QBQueryOrderMap, QueryResult, RequiredEntityData } from '@mikro-orm/core';
|
|
5
5
|
import { LockMode, PopulateHint, QueryFlag } from '@mikro-orm/core';
|
|
6
6
|
import { QueryType } from './enums';
|
|
7
7
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver';
|
|
@@ -35,7 +35,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
35
35
|
private readonly context?;
|
|
36
36
|
private connectionType?;
|
|
37
37
|
private readonly em?;
|
|
38
|
-
private readonly
|
|
38
|
+
private readonly logging?;
|
|
39
39
|
get mainAlias(): Alias;
|
|
40
40
|
get alias(): string;
|
|
41
41
|
get helper(): QueryBuilderHelper;
|
|
@@ -79,7 +79,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
79
79
|
/**
|
|
80
80
|
* @internal
|
|
81
81
|
*/
|
|
82
|
-
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, import("..").AbstractSqlPlatform>> | undefined,
|
|
82
|
+
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, import("..").AbstractSqlPlatform>> | undefined, logging?: LoggingOptions | undefined);
|
|
83
83
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
84
84
|
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
85
85
|
distinct(): SelectQueryBuilder<T>;
|
package/query/QueryBuilder.js
CHANGED
|
@@ -52,13 +52,13 @@ class QueryBuilder {
|
|
|
52
52
|
/**
|
|
53
53
|
* @internal
|
|
54
54
|
*/
|
|
55
|
-
constructor(entityName, metadata, driver, context, alias, connectionType, em,
|
|
55
|
+
constructor(entityName, metadata, driver, context, alias, connectionType, em, logging) {
|
|
56
56
|
this.metadata = metadata;
|
|
57
57
|
this.driver = driver;
|
|
58
58
|
this.context = context;
|
|
59
59
|
this.connectionType = connectionType;
|
|
60
60
|
this.em = em;
|
|
61
|
-
this.
|
|
61
|
+
this.logging = logging;
|
|
62
62
|
/** @internal */
|
|
63
63
|
this._populate = [];
|
|
64
64
|
/** @internal */
|
|
@@ -459,7 +459,7 @@ class QueryBuilder {
|
|
|
459
459
|
return cached.data;
|
|
460
460
|
}
|
|
461
461
|
const type = this.connectionType || (method === 'run' ? 'write' : 'read');
|
|
462
|
-
const res = await this.driver.getConnection(type).execute(query.sql, query.bindings, method, this.context, this.
|
|
462
|
+
const res = await this.driver.getConnection(type).execute(query.sql, query.bindings, method, this.context, this.logging);
|
|
463
463
|
const meta = this.mainAlias.metadata;
|
|
464
464
|
if (!mapResults || !meta) {
|
|
465
465
|
await this.em?.storeCache(this._cache, cached, res);
|