Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: EXPOSED-497 Allow OFFSET without LIMIT in query #2226

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

bog-walk
Copy link
Member

@bog-walk bog-walk commented Sep 5, 2024

Description

Summary of the change:
This makes it possible to generate SELECT query with OFFSET clause that does not require a LIMIT clause.

Detailed description:

  • Why:

The ability to add OFFSET clause is only available through SizedIterable.limit(), forcing some value to also be passed for a LIMIT clause even though most databases support the former without the latter. Using Int.MAX_VALUE may not always be sufficient.

  • What:

It is now possible to append either a LIMIT or an OFFSET clause or both, using DSL or DAO, by chaining SizedIterable.limit().offset() as needed.

  • How:
    • SizedIterable.limit(n, offset) is deprecated and default argument for parameter is removed to avoid conflict with below.
    • SizedIterable interface has 2 new methods: limit(count) and offset(start). They both have default implementations so that any custom implementations of the interface do not break. Only a warning will be raised that there is an override of a deprecated member. This allows time to migrate before deprecation level is bumped and brings a full breaking change.
    • All internal implementations of SizedIterable have had the deprecations propagated and new members implemented.
    • FunctionProvider.queryLimit() is also deprecated and queryLimitAndOffset() is added to accept a nullable size parameter in the event limit() isn't called.

Type of Change

Please mark the relevant options with an "X":

  • New feature

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • Oracle
  • Postgres
  • SqlServer
  • H2

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

EXPOSED-497

All dialects except SQLite and MySQL/MariaDB allow OFFSET clause to be used at the
end of a query without an associated LIMIT clause. This is currently not possible
to accomplish without creating a custom query or providing a very large number,
as a limit must be provided to get an offset.

This splits SizedIterable.limit() into 2 respective functions, introducing a breaking
change for the interface. It also creates a new FunctionProvider.queryLimitAndOffset()
to replace the original, so that a nullable limit can be passed.
- Add default values to new interface members so implementations don't break
- Remove default argument from old limit() to not conflict with new limit()
- Update breaking changes document
@bog-walk bog-walk requested a review from e5l September 5, 2024 16:57
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! we should think about enabling library mode

@bog-walk bog-walk merged commit 13d04b5 into main Sep 9, 2024
5 checks passed
@bog-walk bog-walk deleted the bog-walk/separate-offset-from-limit branch September 9, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants