@mikro-orm/sql 7.2.9-dev.24 → 7.2.9-dev.26
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
CHANGED
|
@@ -342,6 +342,14 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
342
342
|
if (qb) {
|
|
343
343
|
// here we map the aliased results (cartesian product) to an object graph
|
|
344
344
|
this.mapJoinedProps(ret, meta, populate, qb, ret, map);
|
|
345
|
+
// the aliased columns were deleted, which left the row in slow dictionary mode
|
|
346
|
+
if (populate.length > 0) {
|
|
347
|
+
const clean = {};
|
|
348
|
+
for (const key in ret) {
|
|
349
|
+
clean[key] = ret[key];
|
|
350
|
+
}
|
|
351
|
+
return clean;
|
|
352
|
+
}
|
|
345
353
|
}
|
|
346
354
|
return ret;
|
|
347
355
|
}
|
|
@@ -1688,9 +1696,10 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1688
1696
|
if (!Utils.isEmpty(orderBy) || RawQueryFragment.hasObjectFragments(orderBy)) {
|
|
1689
1697
|
return Utils.asArray(orderBy).map(o => ({ [pivotProp.name]: o }));
|
|
1690
1698
|
}
|
|
1691
|
-
if (prop.kind === ReferenceKind.MANY_TO_MANY &&
|
|
1699
|
+
if (prop.kind === ReferenceKind.MANY_TO_MANY &&
|
|
1700
|
+
Utils.asArray(parentOrderBy).some(o => !Utils.isEmpty(o[prop.name]))) {
|
|
1692
1701
|
return Utils.asArray(parentOrderBy)
|
|
1693
|
-
.filter(o => o[prop.name])
|
|
1702
|
+
.filter(o => !Utils.isEmpty(o[prop.name]))
|
|
1694
1703
|
.map(o => ({ [pivotProp.name]: o[prop.name] }));
|
|
1695
1704
|
}
|
|
1696
1705
|
if (!Utils.isEmpty(prop.orderBy) || RawQueryFragment.hasObjectFragments(prop.orderBy)) {
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRaw, JsonProperty, Platform, raw, Utils, ValidationError, } from '@mikro-orm/core';
|
|
1
|
+
import { inspect, isRaw, JsonProperty, Platform, raw, Utils, ValidationError, } from '@mikro-orm/core';
|
|
2
2
|
import { SqlEntityRepository } from './SqlEntityRepository.js';
|
|
3
3
|
import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
|
|
4
4
|
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
@@ -169,9 +169,12 @@ export class AbstractSqlPlatform extends Platform {
|
|
|
169
169
|
* @internal
|
|
170
170
|
*/
|
|
171
171
|
validateOrderByDirection(direction) {
|
|
172
|
-
|
|
172
|
+
if (typeof direction !== 'string') {
|
|
173
|
+
throw new ValidationError(`Invalid order direction: ${inspect(direction)}`);
|
|
174
|
+
}
|
|
175
|
+
const dir = direction.toLowerCase().trim();
|
|
173
176
|
if (!AbstractSqlPlatform.ORDER_BY_DIRECTIONS.has(dir)) {
|
|
174
|
-
throw new
|
|
177
|
+
throw new ValidationError(`Invalid order direction: '${direction}'`);
|
|
175
178
|
}
|
|
176
179
|
return dir;
|
|
177
180
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.9-dev.
|
|
3
|
+
"version": "7.2.9-dev.26",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.2.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.9-dev.26"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIAS_REPLACEMENT, GroupOperator, QueryFlag, raw, RawQueryFragment, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { ALIAS_REPLACEMENT, GroupOperator, QueryFlag, raw, RawQueryFragment, ReferenceKind, Utils, ValidationError, } from '@mikro-orm/core';
|
|
2
2
|
import { CriteriaNode } from './CriteriaNode.js';
|
|
3
3
|
import { JoinType, QueryType } from './enums.js';
|
|
4
4
|
const COLLECTION_OPERATORS = ['$some', '$none', '$every', '$size', '$all'];
|
|
@@ -7,6 +7,9 @@ const COLLECTION_OPERATORS = ['$some', '$none', '$every', '$size', '$all'];
|
|
|
7
7
|
*/
|
|
8
8
|
export class ObjectCriteriaNode extends CriteriaNode {
|
|
9
9
|
process(qb, options) {
|
|
10
|
+
if (options?.type === 'orderBy' && this.prop?.kind === ReferenceKind.SCALAR) {
|
|
11
|
+
throw new ValidationError(`Invalid order direction for ${Utils.className(this.entityName)}.${this.prop.name}`);
|
|
12
|
+
}
|
|
10
13
|
const matchPopulateJoins = options?.matchPopulateJoins ||
|
|
11
14
|
(this.prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(this.prop.kind));
|
|
12
15
|
const nestedAlias = qb.getAliasForJoinPath(this.getPath(options), { ...options, matchPopulateJoins });
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1262,7 +1262,6 @@ export class QueryBuilder {
|
|
|
1262
1262
|
const entities = [];
|
|
1263
1263
|
for (const row of res) {
|
|
1264
1264
|
const entity = this.mapResult(row);
|
|
1265
|
-
this.propagatePopulateHint(entity, this.#state.populate);
|
|
1266
1265
|
entities.push(entity);
|
|
1267
1266
|
if (limit != null && --limit === 0) {
|
|
1268
1267
|
break;
|
|
@@ -1300,7 +1299,9 @@ export class QueryBuilder {
|
|
|
1300
1299
|
* Executes the query, returning both array of results and total count query (without offset and limit).
|
|
1301
1300
|
*/
|
|
1302
1301
|
async getResultAndCount() {
|
|
1303
|
-
|
|
1302
|
+
// `getCount()` clones by itself, except when the type is not set yet
|
|
1303
|
+
const countQb = this.#state.type === undefined ? this.clone() : this;
|
|
1304
|
+
return [await this.clone().getResultList(), await countQb.getCount()];
|
|
1304
1305
|
}
|
|
1305
1306
|
as(aliasOrTargetEntity, alias) {
|
|
1306
1307
|
const qb = this.getNativeQuery();
|
|
@@ -2020,12 +2021,13 @@ export class QueryBuilder {
|
|
|
2020
2021
|
if (meta && (this.#state.fields?.includes('*') || this.#state.fields?.includes(`${this.mainAlias.aliasName}.*`))) {
|
|
2021
2022
|
const schema = this.getSchema(this.mainAlias);
|
|
2022
2023
|
// Per-column entries are unquoted (meant for `quote`), while `toString()` yields the quoted alias for plain template literals
|
|
2023
|
-
// For TPT, use helper to resolve correct alias per property (inherited props use parent alias)
|
|
2024
2024
|
const quotedMainAlias = this.platform.quoteIdentifier(this.mainAlias.aliasName).toString();
|
|
2025
|
-
|
|
2025
|
+
let columns;
|
|
2026
2026
|
meta.props
|
|
2027
2027
|
.filter(prop => prop.formula && (!prop.lazy || this.#state.flags.has(QueryFlag.INCLUDE_LAZY_FORMULAS)))
|
|
2028
2028
|
.map(prop => {
|
|
2029
|
+
// For TPT, use helper to resolve correct alias per property (inherited props use parent alias)
|
|
2030
|
+
columns ??= meta.createColumnMappingObject(p => this.helper.getTPTAliasForProperty(p.name, this.mainAlias.aliasName), quotedMainAlias);
|
|
2029
2031
|
const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
|
|
2030
2032
|
const table = this.helper.createFormulaTable(quotedMainAlias, meta, schema);
|
|
2031
2033
|
return `${this.driver.evaluateFormula(prop.formula, columns, table)} as ${aliased}`;
|
|
@@ -767,33 +767,29 @@ export class QueryBuilderHelper {
|
|
|
767
767
|
if (isRaw(colPart)) {
|
|
768
768
|
colPart = this.#platform.formatQuery(colPart.sql, colPart.params);
|
|
769
769
|
}
|
|
770
|
-
|
|
771
|
-
order.forEach(part => ret.push(...this.getQueryOrderFromObject(type, part, populate, collation)));
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
ret.push(...this.#platform.getOrderByExpression(colPart, order, collation));
|
|
775
|
-
}
|
|
770
|
+
ret.push(...this.#platform.getOrderByExpression(colPart, order, collation));
|
|
776
771
|
}
|
|
777
772
|
}
|
|
778
773
|
return ret;
|
|
779
774
|
}
|
|
780
775
|
splitField(field, greedyAlias = false) {
|
|
781
|
-
const
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
if (
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
776
|
+
const lastDot = field.lastIndexOf('.');
|
|
777
|
+
const colon = field.indexOf(':', lastDot + 1);
|
|
778
|
+
let end = field.length;
|
|
779
|
+
let ref;
|
|
780
|
+
// only the segment between the first and second colon of the last path part is the ref
|
|
781
|
+
if (colon !== -1) {
|
|
782
|
+
const nextColon = field.indexOf(':', colon + 1);
|
|
783
|
+
ref = field.substring(colon + 1, nextColon === -1 ? end : nextColon);
|
|
784
|
+
if (ref) {
|
|
785
|
+
end = colon;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (lastDot === -1) {
|
|
789
|
+
return [this.#alias, field.substring(0, end), ref];
|
|
790
|
+
}
|
|
791
|
+
const aliasEnd = greedyAlias ? lastDot : field.indexOf('.');
|
|
792
|
+
return [field.substring(0, aliasEnd), field.substring(aliasEnd + 1, end), ref];
|
|
797
793
|
}
|
|
798
794
|
getLockSQL(qb, lockMode, lockTables = [], joinsMap) {
|
|
799
795
|
const meta = this.#metadata.find(this.#entityName);
|