-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
support condition objects in utility functions #6666 #6685
Conversation
var run = generator.handleSequelizeMethod.bind(generator); | ||
var expectsql = Support.expectsql | ||
|
||
if (Support.getTestDialect() !== 'mssql') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to skip mssql - It doesn't need to be 100 percent correct syntax (in my mind), as long as it tests the functionality (that you can pass nested conditions)
bar: 'bar' | ||
} | ||
}, 'int'))), { | ||
default: 'SUM(CAST((`foo` = \'foo\' OR `bar` = \'bar\') AS INT))', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default should use [
and ]
for escaping
@@ -226,4 +228,80 @@ describe(Support.getTestDialectTeaser('Utils'), function() { | |||
expect(Utils.singularize('status')).to.equal('status'); | |||
}); | |||
}); | |||
|
|||
describe('Sequelize.fn', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While an integration test might not be strictly needed, I think this is good to keep as an example of how the functionality can be used
You can test MSSQL through AppVeyor ;) |
b8bdf1a
to
a5a4988
Compare
Current coverage is 81.54% (diff: 100%)
|
a5a4988
to
1c4200f
Compare
@janmeier @felixfbecker Thanks for feedback! I addressed some of the comments. I still do not have access to mssql (not even sure if it supports the syntax I am using in the tests). Let me try if I can use appveyor CI runner here to get the tests pass easily but maybe not. |
f18691b
to
4b89420
Compare
I played with mssql and it does not seem to support this syntax. The closest alternative is |
4b89420
to
56c70e8
Compare
Don't forget to mention in the documentation then that this is not supported by MSSQL |
433ce5a
to
f33c5ad
Compare
sequelize#6666 Makes it possible to pass condition objects (e.g. {foo: 'bar'}) to Sequelize.fn(), Sequelize.cast(). This makes it easy to use conditional counts in Sequelize queries, e.g. Sequelize.fn('sum', {name: 'Fred'}) which results in SUM(`name` = 'Fred') which can be used in attribute definition to count entities for which the condition matches.
f33c5ad
to
3329fad
Compare
I modified changelog and added mention to docs. From my POV this change is now finished. Let me know if you find anything missing. |
Thanks 👍 |
@janmeier Thank you! Btw is there a chance to get this into v3 as well? Should I open a new MR against v3? Do you plan further 3.x releases? |
Definitely - Let me see if I can cherry-pick it really quick |
#6666 Makes it possible to pass condition objects (e.g. {foo: 'bar'}) to Sequelize.fn(), Sequelize.cast(). This makes it easy to use conditional counts in Sequelize queries, e.g. Sequelize.fn('sum', {name: 'Fred'}) which results in SUM(`name` = 'Fred') which can be used in attribute definition to count entities for which the condition matches.
75bd525, just going to wait for travis to do his thing before i push a new version |
|
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Future
in the changelog?NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
Description of change
#6666
Makes it possible to pass condition objects (e.g.
{foo: 'bar'}
) toSequelize.fn()
,Sequelize.cast()
.This makes it easy to use conditional counts in Sequelize queries, e.g.
Sequelize.fn('sum', {name: 'Fred'})
which results inSUM(``name``= 'Fred')
which can be used in attribute definition to count entities for which the condition matches.I did not get a chance to test with mssql as I do not have it available. If anyone can do that for me I would appreciate that.