JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.27k stars 690 forks source link

Feat: EXPOSED-396 Supports fetchBatchedResults with sorting order #2102

Closed roharon closed 3 months ago

roharon commented 4 months ago

This PR includes fetchBatchedResults method which supports the sortOrder parameter.

Previously, fetchBatchedResults method only supported the batchSize parameter, making it impossible to handle sorting order as it defaulted to ascending. Adding support for the sortOrder parameter will be helpful.

val cities = DMLTestsData.Cities

cities.selectAll()
      .fetchBatchedResults(batchSize = 25, sortOrder = SortOrder.DESC)
roharon commented 4 months ago

Failed on testMigrationToNewQueryDSL on CI.

But I guess fetchBatchedResults sql query don't need to preserve query as old query dsl. Because (Cities.cityId > 0) query seems like is not necessary.

SELECT Cities.`name` FROM Cities WHERE (Cities.`name` = 'andrey') AND (Cities.cityId > 0) ORDER BY Cities.cityId ASC LIMIT 50

https://github.com/JetBrains/Exposed/blob/8ab66979392374f78a76ed36e2527e09cf8e3364/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt#L50

Iterable elements differ at index 6. Expected element <SELECT Cities.`name` FROM Cities WHERE (Cities.`name` = 'andrey') AND (Cities.cityId > 0) ORDER BY Cities.cityId ASC LIMIT 50>, actual element <SELECT Cities.`name` FROM Cities WHERE Cities.`name` = 'andrey' ORDER BY Cities.cityId ASC LIMIT 50>.
java.lang.AssertionError: Iterable elements differ at index 6. Expected element <SELECT Cities.`name` FROM Cities WHERE (Cities.`name` = 'andrey') AND (Cities.cityId > 0) ORDER BY Cities.cityId ASC LIMIT 50>, actual element <SELECT Cities.`name` FROM Cities WHERE Cities.`name` = 'andrey' ORDER BY Cities.cityId ASC LIMIT 50>.