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

Refactor Query Generator Limit/Offset #10331

Open
mkaufmaner opened this issue Jan 7, 2019 · 1 comment
Open

Refactor Query Generator Limit/Offset #10331

mkaufmaner opened this issue Jan 7, 2019 · 1 comment
Labels
P1: important For issues and PRs. status: in discussion For issues and PRs. Community and maintainers are discussing the applicability of the issue. topic: limit & offset For issues and PRs. Things that involve queries with limit and/or offset. type: refactor For issues and PRs. Things that improve the code readability, maintainability, testability, etc.

Comments

@mkaufmaner
Copy link
Contributor

What are you doing?

Currently the following code in the abstract query generator should be refactored to conform to eslint rules. However, this brings up the question about the implementation and limitations of limit and offset. I dislike the arbitrary implementation of a static count when the offset is passed without a limit. What are the valid values between the support dialects and their versions?

    /* eslint-disable */
    if (options.offset != null && options.limit == null) {
      fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + 10000000000000;
    } else if (options.limit != null) {
      if (options.offset != null) {
        fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + this.escape(options.limit);
      } else {
        fragment += ' LIMIT ' + this.escape(options.limit);
      }
    }
    /* eslint-enable */

Related:

Dialect: any
Dialect version: any
Database version: any
Sequelize version: 5
Tested with latest release: N/A

@mkaufmaner mkaufmaner added status: in discussion For issues and PRs. Community and maintainers are discussing the applicability of the issue. type: refactor For issues and PRs. Things that improve the code readability, maintainability, testability, etc. labels Jan 7, 2019
@javiertury
Copy link
Contributor

In a another issue I argued against limit = 0. I was wrong, all dialects interpret limit = 0 uniformly and return 0 rows. Looking at related issues, some users need the limit = 0 feature. You proposed options.limit !== null && options.limit !== undefined and I think it is adequate.

Perhaps documentation in Pagination / Limiting should explain the difference between limit = 0 and limit = null.

Regarding offset, I think we can safely use if (options.offset). Offset indicates the number of rows to skip, and offset = 0 is equivalent to omitting the offset clause (as mentioned in some docs).

Docs: postgres, mssql, sqlite and mysql

@papb papb added topic: limit & offset For issues and PRs. Things that involve queries with limit and/or offset. P1: important For issues and PRs. labels Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1: important For issues and PRs. status: in discussion For issues and PRs. Community and maintainers are discussing the applicability of the issue. topic: limit & offset For issues and PRs. Things that involve queries with limit and/or offset. type: refactor For issues and PRs. Things that improve the code readability, maintainability, testability, etc.
Projects
None yet
Development

No branches or pull requests

3 participants