@mikro-orm/sql 7.0.0-dev.177 → 7.0.0-dev.178
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.0-dev.
|
|
3
|
+
"version": "7.0.0-dev.178",
|
|
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
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"@mikro-orm/core": "^6.6.4"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.0.0-dev.178"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -325,7 +325,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
325
325
|
getLoggerContext<T extends Dictionary & LoggingOptions = Dictionary>(): T;
|
|
326
326
|
private fromVirtual;
|
|
327
327
|
private joinReference;
|
|
328
|
-
protected prepareFields<T>(fields: Field<T>[], type?: 'where' | 'groupBy' | 'sub-query'): (string | RawQueryFragment)[];
|
|
328
|
+
protected prepareFields<T>(fields: Field<T>[], type?: 'where' | 'groupBy' | 'sub-query', schema?: string): (string | RawQueryFragment)[];
|
|
329
329
|
private init;
|
|
330
330
|
private getQueryBase;
|
|
331
331
|
private applyDiscriminatorCondition;
|
package/query/QueryBuilder.js
CHANGED
|
@@ -555,9 +555,10 @@ export class QueryBuilder {
|
|
|
555
555
|
this._query = {};
|
|
556
556
|
this.finalize();
|
|
557
557
|
const qb = this.getQueryBase(processVirtualEntity);
|
|
558
|
+
const schema = this.getSchema(this.mainAlias);
|
|
558
559
|
const isNotEmptyObject = (obj) => Utils.hasObjectKeys(obj) || RawQueryFragment.hasObjectFragments(obj);
|
|
559
560
|
Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(this.type, this._cond, qb), this._cond && !this._onConflict);
|
|
560
|
-
Utils.runIfNotEmpty(() => qb.groupBy(this.prepareFields(this._groupBy, 'groupBy')), isNotEmptyObject(this._groupBy));
|
|
561
|
+
Utils.runIfNotEmpty(() => qb.groupBy(this.prepareFields(this._groupBy, 'groupBy', schema)), isNotEmptyObject(this._groupBy));
|
|
561
562
|
Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(this.type, this._having, qb, undefined, 'having'), isNotEmptyObject(this._having));
|
|
562
563
|
Utils.runIfNotEmpty(() => {
|
|
563
564
|
const queryOrder = this.helper.getQueryOrder(this.type, this._orderBy, this._populateMap);
|
|
@@ -1014,10 +1015,10 @@ export class QueryBuilder {
|
|
|
1014
1015
|
}
|
|
1015
1016
|
return { prop, key: aliasedName };
|
|
1016
1017
|
}
|
|
1017
|
-
prepareFields(fields, type = 'where') {
|
|
1018
|
+
prepareFields(fields, type = 'where', schema) {
|
|
1018
1019
|
const ret = [];
|
|
1019
1020
|
const getFieldName = (name) => {
|
|
1020
|
-
return this.helper.mapper(name, this.type, undefined, type === 'groupBy' ? null : undefined);
|
|
1021
|
+
return this.helper.mapper(name, this.type, undefined, type === 'groupBy' ? null : undefined, schema);
|
|
1021
1022
|
};
|
|
1022
1023
|
fields.forEach(field => {
|
|
1023
1024
|
if (typeof field !== 'string') {
|
|
@@ -1117,9 +1118,9 @@ export class QueryBuilder {
|
|
|
1117
1118
|
}
|
|
1118
1119
|
switch (this.type) {
|
|
1119
1120
|
case QueryType.SELECT:
|
|
1120
|
-
qb.select(this.prepareFields(this._fields));
|
|
1121
|
+
qb.select(this.prepareFields(this._fields, 'where', schema));
|
|
1121
1122
|
if (this._distinctOn) {
|
|
1122
|
-
qb.distinctOn(this.prepareFields(this._distinctOn));
|
|
1123
|
+
qb.distinctOn(this.prepareFields(this._distinctOn, 'where', schema));
|
|
1123
1124
|
}
|
|
1124
1125
|
else if (this.flags.has(QueryFlag.DISTINCT)) {
|
|
1125
1126
|
qb.distinct();
|
|
@@ -1127,7 +1128,7 @@ export class QueryBuilder {
|
|
|
1127
1128
|
this.helper.processJoins(qb, this._joins, joinSchema);
|
|
1128
1129
|
break;
|
|
1129
1130
|
case QueryType.COUNT: {
|
|
1130
|
-
const fields = this._fields.map(f => this.helper.mapper(f, this.type));
|
|
1131
|
+
const fields = this._fields.map(f => this.helper.mapper(f, this.type, undefined, undefined, schema));
|
|
1131
1132
|
qb.count(fields, this.flags.has(QueryFlag.DISTINCT));
|
|
1132
1133
|
this.helper.processJoins(qb, this._joins, joinSchema);
|
|
1133
1134
|
break;
|
|
@@ -1341,7 +1342,8 @@ export class QueryBuilder {
|
|
|
1341
1342
|
});
|
|
1342
1343
|
}
|
|
1343
1344
|
wrapPaginateSubQuery(meta) {
|
|
1344
|
-
const
|
|
1345
|
+
const schema = this.getSchema(this.mainAlias);
|
|
1346
|
+
const pks = this.prepareFields(meta.primaryKeys, 'sub-query', schema);
|
|
1345
1347
|
const subQuery = this.clone(['_orderBy', '_fields', 'lockMode', 'lockTableAliases']).select(pks).groupBy(pks).limit(this._limit);
|
|
1346
1348
|
// revert the on conditions added via populateWhere, we want to apply those only once
|
|
1347
1349
|
for (const join of Object.values(subQuery._joins)) {
|
|
@@ -1456,7 +1458,8 @@ export class QueryBuilder {
|
|
|
1456
1458
|
// https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause
|
|
1457
1459
|
const subSubQuery = this.platform.createNativeQueryBuilder();
|
|
1458
1460
|
const method = this.flags.has(QueryFlag.UPDATE_SUB_QUERY) ? 'update' : 'delete';
|
|
1459
|
-
const
|
|
1461
|
+
const schema = this.getSchema(this.mainAlias);
|
|
1462
|
+
const pks = this.prepareFields(meta.primaryKeys, 'sub-query', schema);
|
|
1460
1463
|
this._cond = {}; // otherwise we would trigger validation error
|
|
1461
1464
|
this._joins = {}; // included in the subquery
|
|
1462
1465
|
subSubQuery.select(pks).from(subQuery.as(this.mainAlias.aliasName));
|