Repository navigation
Simplify where item query - #8068
Conversation
…ry-generator whereItemQuery by whereItemQuery had cyclic complexity of 85 reduced to 26 to make logic a bit easier to follow. Logic is almost identical but at places where logic looked like an obvoius error it was tweeked, like - _traverseJSON had weird logic if the item was plain object - cast wast set by either path (ok) or the first value of the first property of an object (doesn't make sense) where value passed into whereItemQuery was in the main function scope causing it to accumulate properties on each iteration (doesn't make sense) All test are passing with no issues but since there were minor logic changes there might be some edge cases needed to be addressed. Though it's more resonable to assume changes will fix bugs related to those edge cases than cause them
… sqlite casting and handling of postgres and sqlite handle casting and JSONB formats a bit diffrently yet some previous commits didn't took this changes into consideration when handling casting and didn't test casting properly
…plain js object values for JSON column
|
Working on this I noticed Sequelize eslint rules can benefit from a few extra rules. |
|
Great job 👍 👍 I've had a really hard time when I was working on range types. Thanks a lot 😍 |
|
I skimmed it, and it looks like a decent way to go. |
|
@mickhansen I thought of separating the logic to a different class but didn't want to diverge too much of the original implementation. One small thing though is that currently each dialect have their own query-generator which is being extended by the dialect and being loaded into it. |
I think it would be great if we could seperate it.
It definitely feels a bit off sometimes, open to suggestions. |
I wish I had some concrete suggestion but I have nothing specific to offer at the moment
I looked into it a bit more. And untangling them out of the I can still move the where logic to a separate module but there will need to be some kind of cyclic dependency between it and the query-generator which again feels awkward |
|
@mickhansen do you have an insight on how to separate it or should I leave it as is ? |
|
|
||
| testsql('data', { | ||
| price: 5, | ||
| name: 'Product' |
There was a problem hiding this comment.
Could you add unit tests for boolean and date matching as well
There was a problem hiding this comment.
Do you mean to duplicate each $between and $in tests to include all possible casting types ?
Cause we have tests for those castings in Line 934 and 949.
I added the $between and $in tests because previous logic didn't apply casting at all to them
There was a problem hiding this comment.
Cause we have tests for those castings in Line 934 and 949.
Roger that!
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Abstract dialect query-generator
whereItemQuerymethod was more than 400 lines and had a cyclic complexity of 85. That made it really hard to understand what's going on.Since I have a few other issues which require some changes to this method I thought it would be a lot better if I (and other developers) have better understanding of what's going on before I do even minor logic changes.
I splited the method to smaller private methods.
I tried to converge logic and simplify logic where it was possible.
I also noticed a few bugs in the original implementation which I solved and added tests for
(Issue #3824 which was actually fixed in #4298 but than got overwritten in #7094)