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

Enhance between operators to work with range values #11171

Open
mjy78 opened this issue Jul 9, 2019 · 1 comment
Open

Enhance between operators to work with range values #11171

mjy78 opened this issue Jul 9, 2019 · 1 comment
Labels
status: understood For issues. Applied when the issue is understood / reproducible. topic: operators Features & issues about comparing values inside of WHERE type: feature For issues and PRs. For new features. Never breaking changes.

Comments

@mjy78
Copy link
Contributor

mjy78 commented Jul 9, 2019

Is your feature request related to a problem? Please describe.
Sequelize v5 outputs range types in the format [{value: X, inclusive: true}, {value:Y, inclusive:false}] and this differs to the format provided to the [Op.between] and [Op.notBetween] operators which must be simply [FROM, TO].

This complicates user code that could previously fetch an object with a range property and use this property value directly in a subsequent query on a scalar property with the [Op.between] operator.

Describe the solution you'd like
Enhance the [Op.between] and [Op.notBetween] operators to work with range values in addition to the simple [FROM, TO] array value?

Why should this be in Sequelize
Simplifies new user code and reduces possibility of v5 introducing bugs into existing user code.

Describe alternatives you've considered
The alternative is to do something like:

var item1 = await ModelWithRangeProperty.findOne();
var item2 = await ModelWithScalarProperty.findOne({
  where: {
    scalarProp: { [Op.between]: [item1.rangeProp[0].value, item1.rangeProp[1].value] }
  }
});

Usage example
The user friendly approach (if it could be supported by the between operators) would be:

var item1 = await ModelWithRangeProperty.findOne();
var item2 = await ModelWithScalarProperty.findOne({
  where: {
    scalarProp: { [Op.between]: item1.rangeProp }
  }
});

Additional context
Would it be possible for the between operators to check for the existence of an object with a ".value" property within the FROM/TO values in the array and use these if they exist?

@mjy78 mjy78 added the type: feature For issues and PRs. For new features. Never breaking changes. label Jul 9, 2019
@papb papb added the status: understood For issues. Applied when the issue is understood / reproducible. label Jul 24, 2019
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2021

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 9, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
@ephys ephys added the topic: operators Features & issues about comparing values inside of WHERE label Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: understood For issues. Applied when the issue is understood / reproducible. topic: operators Features & issues about comparing values inside of WHERE type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
Development

No branches or pull requests

4 participants