@mikro-orm/knex 5.7.15-dev.40 → 5.7.15-dev.42
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/AbstractSqlDriver.js +20 -6
- package/package.json +4 -4
- package/query/QueryBuilder.d.ts +12 -0
- package/query/QueryBuilder.js +23 -0
package/AbstractSqlDriver.js
CHANGED
|
@@ -38,6 +38,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
38
38
|
.orderBy([...core_1.Utils.asArray(options.orderBy), ...joinedPropsOrderBy])
|
|
39
39
|
.groupBy(options.groupBy)
|
|
40
40
|
.having(options.having)
|
|
41
|
+
.indexHint(options.indexHint)
|
|
42
|
+
.comment(options.comments)
|
|
43
|
+
.hintComment(options.hintComments)
|
|
41
44
|
.withSchema(this.getSchemaName(meta, options));
|
|
42
45
|
if (options.limit !== undefined) {
|
|
43
46
|
qb.limit(options.limit, options.offset);
|
|
@@ -105,7 +108,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
105
108
|
}
|
|
106
109
|
async wrapVirtualExpressionInSubquery(meta, expression, where, options, type = query_1.QueryType.SELECT) {
|
|
107
110
|
const qb = this.createQueryBuilder(meta.className, options?.ctx, options.connectionType, options.convertCustomTypes)
|
|
108
|
-
.limit(options?.limit, options?.offset)
|
|
111
|
+
.limit(options?.limit, options?.offset)
|
|
112
|
+
.indexHint(options.indexHint)
|
|
113
|
+
.comment(options.comments)
|
|
114
|
+
.hintComment(options.hintComments);
|
|
109
115
|
if (options.orderBy) {
|
|
110
116
|
qb.orderBy(options.orderBy);
|
|
111
117
|
}
|
|
@@ -207,6 +213,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
207
213
|
return this.countVirtual(entityName, where, options);
|
|
208
214
|
}
|
|
209
215
|
const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false)
|
|
216
|
+
.indexHint(options.indexHint)
|
|
217
|
+
.comment(options.comments)
|
|
218
|
+
.hintComment(options.hintComments)
|
|
210
219
|
.groupBy(options.groupBy)
|
|
211
220
|
.having(options.having)
|
|
212
221
|
.populate(options.populate ?? [])
|
|
@@ -501,17 +510,22 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
501
510
|
else {
|
|
502
511
|
where = { ...where, ...cond };
|
|
503
512
|
}
|
|
513
|
+
/* istanbul ignore if */
|
|
514
|
+
options = { ...options };
|
|
504
515
|
orderBy = this.getPivotOrderBy(prop, orderBy);
|
|
505
|
-
const qb = this.createQueryBuilder(prop.type, ctx, options
|
|
516
|
+
const qb = this.createQueryBuilder(prop.type, ctx, options.connectionType)
|
|
517
|
+
.indexHint(options.indexHint)
|
|
518
|
+
.comment(options.comments)
|
|
519
|
+
.hintComment(options.hintComments)
|
|
506
520
|
.unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES)
|
|
507
521
|
.withSchema(this.getSchemaName(prop.targetMeta, options));
|
|
508
522
|
const populate = this.autoJoinOneToOneOwner(prop.targetMeta, [{ field: prop.pivotEntity }]);
|
|
509
|
-
const fields = this.buildFields(prop.targetMeta, (options
|
|
510
|
-
qb.select(fields).populate(populate).where(where).orderBy(orderBy).setLockMode(options
|
|
511
|
-
if (owners.length === 1 && (options
|
|
523
|
+
const fields = this.buildFields(prop.targetMeta, (options.populate ?? []), [], qb, options.fields);
|
|
524
|
+
qb.select(fields).populate(populate).where(where).orderBy(orderBy).setLockMode(options.lockMode, options.lockTableAliases);
|
|
525
|
+
if (owners.length === 1 && (options.offset != null || options.limit != null)) {
|
|
512
526
|
qb.limit(options.limit, options.offset);
|
|
513
527
|
}
|
|
514
|
-
if (prop.targetMeta.schema !== '*' && pivotMeta.schema === '*' && options
|
|
528
|
+
if (prop.targetMeta.schema !== '*' && pivotMeta.schema === '*' && options.schema) {
|
|
515
529
|
// eslint-disable-next-line dot-notation
|
|
516
530
|
qb['finalize']();
|
|
517
531
|
// eslint-disable-next-line dot-notation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "5.7.15-dev.
|
|
3
|
+
"version": "5.7.15-dev.42",
|
|
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,9 +66,9 @@
|
|
|
66
66
|
"@mikro-orm/core": "^5.7.14"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~5.7.15-dev.
|
|
70
|
-
"@mikro-orm/entity-generator": "~5.7.15-dev.
|
|
71
|
-
"@mikro-orm/migrations": "~5.7.15-dev.
|
|
69
|
+
"@mikro-orm/core": "~5.7.15-dev.42",
|
|
70
|
+
"@mikro-orm/entity-generator": "~5.7.15-dev.42",
|
|
71
|
+
"@mikro-orm/migrations": "~5.7.15-dev.42",
|
|
72
72
|
"better-sqlite3": "*",
|
|
73
73
|
"mssql": "*",
|
|
74
74
|
"mysql": "*",
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
66
66
|
private _joinedProps;
|
|
67
67
|
private _cache?;
|
|
68
68
|
private _indexHint?;
|
|
69
|
+
private _comments;
|
|
70
|
+
private _hintComments;
|
|
69
71
|
private flushMode?;
|
|
70
72
|
private lockMode?;
|
|
71
73
|
private lockTables?;
|
|
@@ -132,6 +134,16 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
132
134
|
* Adds index hint to the FROM clause.
|
|
133
135
|
*/
|
|
134
136
|
indexHint(sql: string): this;
|
|
137
|
+
/**
|
|
138
|
+
* Prepend comment to the sql query using the syntax `/* ... *‍/`. Some characters are forbidden such as `/*, *‍/` and `?`.
|
|
139
|
+
*/
|
|
140
|
+
comment(comment: string | string[]): this;
|
|
141
|
+
/**
|
|
142
|
+
* Add hints to the query using comment-like syntax `/*+ ... *‍/`. MySQL and Oracle use this syntax for optimizer hints.
|
|
143
|
+
* Also various DB proxies and routers use this syntax to pass hints to alter their behavior. In other dialects the hints
|
|
144
|
+
* are ignored as simple comments.
|
|
145
|
+
*/
|
|
146
|
+
hintComment(comment: string | string[]): this;
|
|
135
147
|
/**
|
|
136
148
|
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
137
149
|
* Allows setting a main string alias of the selection data.
|
package/query/QueryBuilder.js
CHANGED
|
@@ -60,6 +60,8 @@ class QueryBuilder {
|
|
|
60
60
|
this._groupBy = [];
|
|
61
61
|
this._having = {};
|
|
62
62
|
this._joinedProps = new Map();
|
|
63
|
+
this._comments = [];
|
|
64
|
+
this._hintComments = [];
|
|
63
65
|
this.subQueries = {};
|
|
64
66
|
this._aliases = {};
|
|
65
67
|
this.platform = this.driver.getPlatform();
|
|
@@ -352,6 +354,24 @@ class QueryBuilder {
|
|
|
352
354
|
this._indexHint = sql;
|
|
353
355
|
return this;
|
|
354
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Prepend comment to the sql query using the syntax `/* ... *‍/`. Some characters are forbidden such as `/*, *‍/` and `?`.
|
|
359
|
+
*/
|
|
360
|
+
comment(comment) {
|
|
361
|
+
this.ensureNotFinalized();
|
|
362
|
+
this._comments.push(...core_1.Utils.asArray(comment));
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Add hints to the query using comment-like syntax `/*+ ... *‍/`. MySQL and Oracle use this syntax for optimizer hints.
|
|
367
|
+
* Also various DB proxies and routers use this syntax to pass hints to alter their behavior. In other dialects the hints
|
|
368
|
+
* are ignored as simple comments.
|
|
369
|
+
*/
|
|
370
|
+
hintComment(comment) {
|
|
371
|
+
this.ensureNotFinalized();
|
|
372
|
+
this._hintComments.push(...core_1.Utils.asArray(comment));
|
|
373
|
+
return this;
|
|
374
|
+
}
|
|
355
375
|
from(target, aliasName) {
|
|
356
376
|
this.ensureNotFinalized();
|
|
357
377
|
if (target instanceof QueryBuilder) {
|
|
@@ -381,6 +401,8 @@ class QueryBuilder {
|
|
|
381
401
|
}, this._orderBy);
|
|
382
402
|
core_1.Utils.runIfNotEmpty(() => qb.limit(this._limit), this._limit != null);
|
|
383
403
|
core_1.Utils.runIfNotEmpty(() => qb.offset(this._offset), this._offset);
|
|
404
|
+
core_1.Utils.runIfNotEmpty(() => this._comments.forEach(comment => qb.comment(comment)), this._comments);
|
|
405
|
+
core_1.Utils.runIfNotEmpty(() => this._hintComments.forEach(comment => qb.hintComment(comment)), this._hintComments);
|
|
384
406
|
core_1.Utils.runIfNotEmpty(() => this.helper.appendOnConflictClause(this.type ?? enums_1.QueryType.SELECT, this._onConflict, qb), this._onConflict);
|
|
385
407
|
if (this.type === enums_1.QueryType.TRUNCATE && this.platform.usesCascadeStatement()) {
|
|
386
408
|
return this.knex.raw(qb.toSQL().toNative().sql + ' cascade');
|
|
@@ -577,6 +599,7 @@ class QueryBuilder {
|
|
|
577
599
|
const properties = [
|
|
578
600
|
'flags', '_populate', '_populateWhere', '_populateMap', '_joins', '_joinedProps', '_cond', '_data', '_orderBy',
|
|
579
601
|
'_schema', '_indexHint', '_cache', 'subQueries', 'lockMode', 'lockTables', '_groupBy', '_having', '_returning',
|
|
602
|
+
'_comments', '_hintComments',
|
|
580
603
|
];
|
|
581
604
|
properties.forEach(prop => qb[prop] = core_1.Utils.copy(this[prop]));
|
|
582
605
|
/* istanbul ignore else */
|