@mikro-orm/sql 7.0.4-dev.1 → 7.0.4-dev.3
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 +2 -2
- package/query/QueryBuilder.d.ts +3 -2
- package/query/QueryBuilder.js +39 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.4-dev.
|
|
3
|
+
"version": "7.0.4-dev.3",
|
|
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.0.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.0.4-dev.
|
|
56
|
+
"@mikro-orm/core": "7.0.4-dev.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -125,8 +125,9 @@ type TypedAliasedFilterValue<T> = FilterValue<ExpandProperty<T>> | QueryBuilder<
|
|
|
125
125
|
type RootAliasFilterKeys<RootAlias extends string, Entity> = {
|
|
126
126
|
[K in EntityKey<Entity> as `${RootAlias}.${K}`]?: TypedAliasedFilterValue<Entity[K]>;
|
|
127
127
|
};
|
|
128
|
+
type ContextFieldType<Context, K extends string> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, infer Type, any] ? K extends `${Alias & string}.${infer Prop}` ? Prop extends keyof Type ? TypedAliasedFilterValue<Type[Prop]> : never : never : never : never : never;
|
|
128
129
|
type ContextFilterKeys<Context> = {
|
|
129
|
-
[K in ContextFieldKeys<Context>]?:
|
|
130
|
+
[K in ContextFieldKeys<Context>]?: ContextFieldType<Context, K>;
|
|
130
131
|
};
|
|
131
132
|
type RawFilterKeys<RawAliases extends string> = {
|
|
132
133
|
[K in RawAliases]?: AliasedFilterValue;
|
|
@@ -923,7 +924,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
923
924
|
/**
|
|
924
925
|
* Removes joins that are not used for population or ordering to improve performance.
|
|
925
926
|
*/
|
|
926
|
-
protected pruneJoinsForPagination(
|
|
927
|
+
protected pruneJoinsForPagination(): void;
|
|
927
928
|
/**
|
|
928
929
|
* Transfers WHERE conditions that reference a join alias to the join's ON clause.
|
|
929
930
|
* This is needed when a join is kept for ORDER BY after pagination wrapping,
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1988,7 +1988,7 @@ export class QueryBuilder {
|
|
|
1988
1988
|
const originalCond = this.#state.cond;
|
|
1989
1989
|
const populatePaths = this.getPopulatePaths();
|
|
1990
1990
|
if (!this.#state.fields.some(field => isRaw(field))) {
|
|
1991
|
-
this.pruneJoinsForPagination(
|
|
1991
|
+
this.pruneJoinsForPagination();
|
|
1992
1992
|
}
|
|
1993
1993
|
// Transfer WHERE conditions to ORDER BY joins (GH #6160)
|
|
1994
1994
|
this.transferConditionsForOrderByJoins(meta, originalCond, populatePaths);
|
|
@@ -2043,23 +2043,51 @@ export class QueryBuilder {
|
|
|
2043
2043
|
/**
|
|
2044
2044
|
* Removes joins that are not used for population or ordering to improve performance.
|
|
2045
2045
|
*/
|
|
2046
|
-
pruneJoinsForPagination(
|
|
2047
|
-
const orderByAliases = this.#state.orderBy.flatMap(hint => Object.keys(hint)).map(k => k.split('.')[0]);
|
|
2046
|
+
pruneJoinsForPagination() {
|
|
2048
2047
|
const joins = Object.entries(this.#state.joins);
|
|
2049
2048
|
const rootAlias = this.alias;
|
|
2050
|
-
|
|
2049
|
+
const keptAliases = new Set();
|
|
2050
|
+
// Collect aliases needed for ORDER BY
|
|
2051
|
+
for (const hint of this.#state.orderBy) {
|
|
2052
|
+
for (const k of Object.keys(hint)) {
|
|
2053
|
+
if (!RawQueryFragment.isKnownFragmentSymbol(k)) {
|
|
2054
|
+
keptAliases.add(k.split('.')[0]);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
// Collect aliases needed for population (joined strategy):
|
|
2059
|
+
// 1. Joins tracked in populateMap (OneToOne inverse from processPopulateHint)
|
|
2060
|
+
// 2. Joins tracked in joinedProps (manual joinAndSelect calls)
|
|
2061
|
+
// 3. Joins whose alias is referenced in SELECT fields (JOINED strategy populate fields)
|
|
2062
|
+
for (const [key, join] of joins) {
|
|
2063
|
+
if (key in this.#state.populateMap || this.#state.joinedProps.has(join.alias)) {
|
|
2064
|
+
keptAliases.add(join.alias);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
// Check SELECT fields for alias references - keeps joins needed for data loading
|
|
2068
|
+
if (this.#state.fields) {
|
|
2069
|
+
for (const field of this.#state.fields) {
|
|
2070
|
+
const fieldStr = typeof field === 'string' ? field : isRaw(field) ? field.sql : '';
|
|
2071
|
+
for (const [, join] of joins) {
|
|
2072
|
+
if (fieldStr.includes(`${join.alias}.`) || fieldStr.includes(`${join.alias}__`)) {
|
|
2073
|
+
keptAliases.add(join.alias);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
// Also keep parent joins of all kept aliases (e.g. pivot tables for M:N)
|
|
2079
|
+
function addParentAliases(alias) {
|
|
2051
2080
|
const join = joins.find(j => j[1].alias === alias);
|
|
2052
|
-
if (join && join[1].ownerAlias !== rootAlias) {
|
|
2053
|
-
|
|
2054
|
-
|
|
2081
|
+
if (join && join[1].ownerAlias !== rootAlias && !keptAliases.has(join[1].ownerAlias)) {
|
|
2082
|
+
keptAliases.add(join[1].ownerAlias);
|
|
2083
|
+
addParentAliases(join[1].ownerAlias);
|
|
2055
2084
|
}
|
|
2056
2085
|
}
|
|
2057
|
-
for (const
|
|
2058
|
-
|
|
2086
|
+
for (const alias of [...keptAliases]) {
|
|
2087
|
+
addParentAliases(alias);
|
|
2059
2088
|
}
|
|
2060
2089
|
for (const [key, join] of joins) {
|
|
2061
|
-
|
|
2062
|
-
if (!populatePaths.has(path) && !orderByAliases.includes(join.alias)) {
|
|
2090
|
+
if (!keptAliases.has(join.alias)) {
|
|
2063
2091
|
delete this.#state.joins[key];
|
|
2064
2092
|
}
|
|
2065
2093
|
}
|