@mikro-orm/sql 7.2.2-dev.10 → 7.2.2-dev.12
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.2.2-dev.
|
|
3
|
+
"version": "7.2.2-dev.12",
|
|
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.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.2-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.2-dev.12"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1566,7 +1566,7 @@ export class QueryBuilder {
|
|
|
1566
1566
|
return;
|
|
1567
1567
|
}
|
|
1568
1568
|
if (prop?.embedded || (prop?.kind === ReferenceKind.EMBEDDED && prop.object)) {
|
|
1569
|
-
const name = prop.embeddedPath?.join('.') ?? prop.fieldNames[0];
|
|
1569
|
+
const name = prop.formula ? prop.name : (prop.embeddedPath?.join('.') ?? prop.fieldNames[0]);
|
|
1570
1570
|
const aliased = this.#state.aliases[a] ? `${a}.${name}` : name;
|
|
1571
1571
|
ret.push(getFieldName(aliased, customAlias));
|
|
1572
1572
|
return;
|
|
@@ -1581,11 +1581,11 @@ export class QueryBuilder {
|
|
|
1581
1581
|
}
|
|
1582
1582
|
const nest = (prop) => {
|
|
1583
1583
|
for (const childProp of Object.values(prop.embeddedProps)) {
|
|
1584
|
-
if (childProp.persist === false) {
|
|
1584
|
+
if (childProp.persist === false && !childProp.formula) {
|
|
1585
1585
|
continue;
|
|
1586
1586
|
}
|
|
1587
1587
|
if (childProp.fieldNames && (childProp.kind !== ReferenceKind.EMBEDDED || childProp.object)) {
|
|
1588
|
-
const name = childProp.fieldNames[0];
|
|
1588
|
+
const name = childProp.formula ? childProp.name : childProp.fieldNames[0];
|
|
1589
1589
|
ret.push(getFieldName(this.#state.aliases[a] ? `${a}.${name}` : name));
|
|
1590
1590
|
}
|
|
1591
1591
|
else {
|
|
@@ -1666,7 +1666,8 @@ export class QueryBuilder {
|
|
|
1666
1666
|
return `${currentAlias}.${embeddedProp.fieldNames[0]}`;
|
|
1667
1667
|
}
|
|
1668
1668
|
}
|
|
1669
|
-
|
|
1669
|
+
const name = embeddedProp?.formula ? embeddedProp.name : (embeddedProp?.fieldNames?.[0] ?? propName);
|
|
1670
|
+
return `${currentAlias}.${name}`;
|
|
1670
1671
|
}
|
|
1671
1672
|
// Handle relations - auto-join if not the last part
|
|
1672
1673
|
if (prop.kind === ReferenceKind.MANY_TO_ONE ||
|
|
@@ -2322,7 +2323,10 @@ export class QueryBuilder {
|
|
|
2322
2323
|
const fieldName = this.helper.mapper(field, this.type, undefined, null);
|
|
2323
2324
|
// virtual fields (e.g. `qb.as(...)`) have no column to reference inside `min()`; inline their
|
|
2324
2325
|
// expression instead, as a select alias is not resolvable there on some dialects (e.g. PostgreSQL)
|
|
2325
|
-
const virtual = !prop
|
|
2326
|
+
const virtual = (!prop || prop.persist === false) &&
|
|
2327
|
+
!prop?.formula &&
|
|
2328
|
+
!prop?.hasConvertToJSValueSQL &&
|
|
2329
|
+
!pks.includes(fieldName)
|
|
2326
2330
|
? this.resolveVirtualField(f, fieldName)
|
|
2327
2331
|
: undefined;
|
|
2328
2332
|
const expr = virtual ? virtual.expr : this.platform.quoteIdentifier(fieldName);
|
|
@@ -112,7 +112,7 @@ export class QueryBuilderHelper {
|
|
|
112
112
|
const aliasPrefix = isTableNameAliasRequired ? resolvedAlias + '.' : '';
|
|
113
113
|
const fkIdx2 = prop?.fieldNames.findIndex(name => name === f) ?? -1;
|
|
114
114
|
const fkIdx = fkIdx2 === -1 ? 0 : fkIdx2;
|
|
115
|
-
if (a === prop?.embedded?.[0]) {
|
|
115
|
+
if (a === prop?.embedded?.[0] && !prop.formula) {
|
|
116
116
|
return aliasPrefix + prop.fieldNames[fkIdx];
|
|
117
117
|
}
|
|
118
118
|
const noPrefix = prop?.persist === false;
|
|
@@ -120,12 +120,13 @@ export class QueryBuilderHelper {
|
|
|
120
120
|
return raw(this.prefix(field, isTableNameAliasRequired));
|
|
121
121
|
}
|
|
122
122
|
if (prop?.formula) {
|
|
123
|
-
const
|
|
123
|
+
const formulaAlias = isTableAlias ? a : this.#alias;
|
|
124
|
+
const alias2 = this.#platform.quoteIdentifier(formulaAlias).toString();
|
|
124
125
|
const aliasName = alias === undefined ? prop.fieldNames[0] : alias;
|
|
125
126
|
const as = aliasName === null ? '' : ` as ${this.#platform.quoteIdentifier(aliasName)}`;
|
|
126
127
|
const meta = this.#aliasMap[a]?.meta ?? this.#metadata.get(this.#entityName);
|
|
127
128
|
const table = this.createFormulaTable(alias2, meta, schema);
|
|
128
|
-
const columns = meta.createColumnMappingObject(p => this.getTPTAliasForProperty(p.name,
|
|
129
|
+
const columns = meta.createColumnMappingObject(p => this.getTPTAliasForProperty(p.name, formulaAlias), alias2);
|
|
129
130
|
let value = this.#driver.evaluateFormula(prop.formula, columns, table);
|
|
130
131
|
if (!this.isTableNameAliasRequired(type)) {
|
|
131
132
|
value = value.replaceAll(alias2 + '.', '');
|