Fix inner query sort limit (#16922)

* Add sort within inner query

* Run tests for all vendors

* Apply limit to all queries

* Enable sorting in MSSQL subquery by setting a limit

* Add tests

* Parse function field names for a2o

* Improve order string spacing

* Update unit test

* Fix mysql5 tests

* Revert testing for all vendors

* Extract original collection name

* Add comment for MSSQL applyLimit helper

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
This commit is contained in:
ian
2023-01-04 18:43:17 +07:00
committed by GitHub
parent 04497ccbd7
commit 802dfa0703
10 changed files with 3127 additions and 1187 deletions

View File

@@ -43,9 +43,7 @@ export default function applyQuery(
applySort(knex, schema, dbQuery, query.sort, collection, aliasMap);
}
if (!options?.hasMultiRelationalSort) {
applyLimit(dbQuery, query.limit);
}
applyLimit(knex, dbQuery, query.limit);
if (query.offset) {
applyOffset(knex, dbQuery, query.offset);
@@ -311,9 +309,9 @@ export function applySort(
rootQuery.orderBy(sortRecords);
}
export function applyLimit(rootQuery: Knex.QueryBuilder, limit: any) {
if (typeof limit === 'number' && limit !== -1) {
rootQuery.limit(limit);
export function applyLimit(knex: Knex, rootQuery: Knex.QueryBuilder, limit: any) {
if (typeof limit === 'number') {
getHelpers(knex).schema.applyLimit(rootQuery, limit);
}
}