kysely-hydrate 0.10.1 → 0.10.2
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/dist/index.mjs +10 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -807,12 +807,16 @@ var QuerySetImpl = class QuerySetImpl {
|
|
|
807
807
|
if (offset !== null) qb = qb.offset(offset);
|
|
808
808
|
return qb;
|
|
809
809
|
}
|
|
810
|
-
#applyOrderBy(qb) {
|
|
810
|
+
#applyOrderBy(qb, isOuter = false) {
|
|
811
811
|
const { baseAlias, keyBy, orderBy } = this.#props;
|
|
812
|
+
const eb = k.expressionBuilder(qb);
|
|
812
813
|
let keyByArray = typeof keyBy === "string" ? [keyBy] : keyBy;
|
|
813
814
|
for (const { expr, modifiers } of orderBy) {
|
|
814
|
-
|
|
815
|
-
|
|
815
|
+
let orderExpr;
|
|
816
|
+
if (expr.includes(SEP)) if (isOuter) orderExpr = eb.ref(`${baseAlias}.${expr}`);
|
|
817
|
+
else orderExpr = expr.replace(SEP, ".");
|
|
818
|
+
else orderExpr = `${baseAlias}.${expr}`;
|
|
819
|
+
qb = qb.orderBy(orderExpr, modifiers);
|
|
816
820
|
keyByArray = keyByArray.filter((k$1) => k$1 !== expr);
|
|
817
821
|
}
|
|
818
822
|
if (this.#props.orderByKeys) for (const key of keyByArray) qb = qb.orderBy(`${baseAlias}.${key}`, "asc");
|
|
@@ -838,7 +842,7 @@ var QuerySetImpl = class QuerySetImpl {
|
|
|
838
842
|
const { joinCollections } = this.#props;
|
|
839
843
|
let qb = this.#getSelectFromBase(isNested, isLocalSubquery);
|
|
840
844
|
for (const [key, collection] of joinCollections) qb = this.#addCollectionAsJoin(qb, key, collection);
|
|
841
|
-
if (!(isNested || isLocalSubquery)) qb = this.#applyOrderBy(qb);
|
|
845
|
+
if (!(isNested || isLocalSubquery)) qb = this.#applyOrderBy(qb, false);
|
|
842
846
|
return qb;
|
|
843
847
|
}
|
|
844
848
|
toJoinedQuery() {
|
|
@@ -858,12 +862,12 @@ var QuerySetImpl = class QuerySetImpl {
|
|
|
858
862
|
if (this.#isCardinalityOne()) return this.#applyLimitAndOffset(this.#toJoinedQuery(isNested, isLocalSubquery));
|
|
859
863
|
let cardinalityOneQuery = this.#toCardinalityOneQuery(isNested, isLocalSubquery);
|
|
860
864
|
cardinalityOneQuery = this.#applyLimitAndOffset(cardinalityOneQuery);
|
|
861
|
-
if (limit || offset) cardinalityOneQuery = this.#applyOrderBy(cardinalityOneQuery);
|
|
865
|
+
if (limit || offset) cardinalityOneQuery = this.#applyOrderBy(cardinalityOneQuery, false);
|
|
862
866
|
const aliasedCardinalityOneQuery = cardinalityOneQuery.as(baseAlias);
|
|
863
867
|
let qb = db.selectFrom(aliasedCardinalityOneQuery);
|
|
864
868
|
qb = applyHoistedSelections(qb, cardinalityOneQuery, baseAlias);
|
|
865
869
|
for (const [key, collection] of joinCollections) if (!this.#isCollectionCardinalityOne(collection)) qb = this.#addCollectionAsJoin(qb, key, collection);
|
|
866
|
-
if (!(isNested || isLocalSubquery)) qb = this.#applyOrderBy(qb);
|
|
870
|
+
if (!(isNested || isLocalSubquery)) qb = this.#applyOrderBy(qb, true);
|
|
867
871
|
for (const modifier of this.#props.frontModifiers) qb = qb.modifyFront(modifier);
|
|
868
872
|
for (const modifier of this.#props.endModifiers) qb = qb.modifyEnd(modifier);
|
|
869
873
|
return qb;
|