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

feat: combine equalTo clauses with clauses #1373

Open
wants to merge 13 commits into
base: alpha
Choose a base branch
from

Conversation

sadakchap
Copy link
Member

@sadakchap sadakchap commented Jun 8, 2021

New Pull Request Checklist

Issue Description

equalTo query overrides any existing clauses before it. For e.g.

let q = new Parse.Query('MyClass');
q.greaterThan('age', 10);
q.equalTo('age', 9);
// this will override $gt query and will result something like this where: { age : 9 }

Related issue: #1372

Approach

After following through #1372 and parse-community/parse-php-sdk#476 and #1372 (comment).

Using this.addCondition(key, $eq, value) instead this.where[key], so that equalTo clause can be combined with other clauses and vice-versa.

TODOs before merging

  • Add tests
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

@sadakchap do you mind to look at the failing tests?

Overall I like the idea. @dplewis what do you think?

@mtrezza
Copy link
Member

mtrezza commented Sep 10, 2021

have added only a failing test case.

@sadakchap it seems you have actually also added the fix in this PR, correct? If so, is this ready for review? I would like to add the related dashboard feature with the null filter.

@sadakchap
Copy link
Member Author

If so, is this ready for review? I would like to add the related dashboard feature with the null filter.

Thanks @mtrezza , I think it still has some failing tests. I will try to fix those during this weekend and will let you know 🙂

@sadakchap sadakchap changed the title Combine equalTo clause with other clauses feat: combine equalTo clauses with clauses Sep 22, 2021
@parse-github-assistant
Copy link

parse-github-assistant bot commented Sep 22, 2021

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@sadakchap
Copy link
Member Author

@mtrezza Thanks for following up & waiting.

About failing test cases. Only Live Query test are failing as they depend on parse-server to fire events. We will need to update parse-server to send events for $eq queries in order to fix all failing test case.

@sadakchap
Copy link
Member Author

Here's the pr with added support for $eq query for LiveQuery.

@mtrezza @davimacedo @dplewis, would really like to hear your thoughts about it?

@@ -1222,7 +1222,8 @@ class ParseQuery {
return this.doesNotExist(key);
}

this._where[key] = encode(value, false, true);
// this._where[key] = encode(value, false, true);
Copy link
Member

Choose a reason for hiding this comment

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

This comment seems to be a leftover?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update the pr once all checks are passing.

@@ -301,7 +301,9 @@ describe('CloudController', () => {
expect(data).toEqual({
limit: 1,
where: {
objectId: 'jobId1234',
Copy link
Member

Choose a reason for hiding this comment

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

Should all these tests be modified? That means the original syntax would not be tested anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, all test are modified. And yes, original syntax would not be tested anymore as it will always make any equalTo query with this updated syntax { $eq: '' }

Copy link
Member

Choose a reason for hiding this comment

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

Could that be a breaking change for existing deployments?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see it as a breaking change, as it will just change the syntax of query for equalTo, everything else should be same.

For adding equalTo query, we still would be doing same thing.

q.equalTo('age', 10); // same implementation, just query that will be sent is of new syntax.

Copy link
Member

Choose a reason for hiding this comment

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

Does this mean the query sent to the DB has a different syntax, or only the query sent to Parse Server?

@@ -136,6 +140,7 @@ describe('ParseQuery', () => {
expect(q.toJSON()).toEqual({
where: {
size: {
$eq: 'small',
Copy link
Member

Choose a reason for hiding this comment

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

It seems strange that this results in $eq:small and $exists:false, isn't that a contradiction?

The comment assumed: equalTo('key', undefined) resolves to 'does not exist'
But in this case it just adds dne to the query, which probably results in a different query sent to the DB?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, It is contradiction. 😕

Suggestion: Maybe we can make $exists override $eq clause.

Problem: this pr is in response to this #1372, which was created due to this pr, where we were trying to make a query something like this(for filtering values which are null & exists)

where: { age: { $eq: null, $exists: true } }

which again won't be possible if $exists can't be combined with $eq

stock: true,
size: {
$eq: 'medium',
$exists: false,
Copy link
Member

Choose a reason for hiding this comment

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

This also looks strange

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants