Skip to content

fix(types): correct typing definitions for Sequelize.where - #14018

Merged
ephys merged 9 commits into
mainfrom
ephys/fix-where-typing
Feb 2, 2022
Merged

ephys merged 9 commits into
mainfrom
ephys/fix-where-typing

Conversation

@ephys

@ephys ephys commented Jan 26, 2022 •

Copy link
Copy Markdown
Member

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description Of Change

The typings for Sequelize.where(leftOperand, operator, rightOperand) were very incorrect:

  • It stated that the left operand accepted strings, but that is not the case. Using a string as the left operand will crash.
  • The typings for operator accepted strings. It works but users should use Op symbols. I can revert this change but the typing would not be great.
  • The typings for rightOperand were all over the place. I've now delegated them to WhereOperators so where accepts the same values as the POJO version.
    i.e. in where(col('first_name'), Op.iLike, name), name will be accept the exact same values as { firstName: { [Op.iLike]: name } }.

The signature used to be where(attribute, comparator, logic) but I've renamed it to where(leftOperand, operator, rightOperand) which is much closer to reality as the operands can be much more than just an attribute.

I've also added tests for things the JSDoc says are supported but were not tested.

I have not updated the typings for lib/utils/Where as it's internal and the changes I want to make would impact a lot more files - but I'd like to refactor it for v7 in #13782

- string is not accepted in `leftOperand`
- `rightOperand` is operator-dependant
- `operator` can only be a symbol
@ephys ephys self-assigned this Jan 26, 2022
@ephys ephys added the typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. label Jan 26, 2022
@ephys
ephys requested review from WikiRik, sdepold and wbourne0 January 26, 2022 10:01
sdepold
sdepold previously approved these changes Jan 26, 2022

@sdepold sdepold left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tbh... I didn't even know that you can pass anything other than an object to where 🙈 so you have my trust

@ephys

ephys commented Jan 26, 2022 •

Copy link
Copy Markdown
Member Author

It's for those couple use-cases where you need to use fn on your column :)

Before merging, I'll re-add string as a valid operator. I don't want to add a breaking change in v6.
We'll see in https://github.com/sequelize/sequelize/tree/ephys/new-where-builder in the future if we want to remove it

Edit: that is now done

@ephys ephys mentioned this pull request Jan 28, 2022
4 of 6 tasks

@wbourne0 wbourne0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I haven't used where as a function personally, but the types look fine and I trust your judgement so lgtm.

@ephys

ephys commented Feb 2, 2022

Copy link
Copy Markdown
Member Author

Thanks :) Here we go then

@ephys
ephys merged commit 308ace0 into main Feb 2, 2022
@ephys
ephys deleted the ephys/fix-where-typing branch February 2, 2022 10:33
ephys added a commit that referenced this pull request Feb 6, 2022
@ephys ephys mentioned this pull request Feb 6, 2022
ephys added a commit that referenced this pull request Feb 6, 2022
ephys added a commit that referenced this pull request Feb 6, 2022
@github-actions

github-actions Bot commented Feb 7, 2022

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 7.0.0-alpha.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

aliatsis pushed a commit to creditiq/sequelize that referenced this pull request Jun 2, 2022
vanthome pushed a commit to vanthome/sequelize that referenced this pull request Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released on @v7 typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants