-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New query condition support to match all strings that starts with some other given strings #3864
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
New query condition support to match all strings that starts with some other given strings #3864
Conversation
Thanks for the PR, this looks great but could you add proper edge to edge test with |
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.
Edge to edge tests would be nice, postgres support would be awesome.
@flovilmart I can't really say. I haven't actually used parse-server for anything yet. Just doing support as far as |
Codecov Report
@@ Coverage Diff @@
## master #3864 +/- ##
==========================================
+ Coverage 90.14% 90.47% +0.32%
==========================================
Files 114 114
Lines 7550 7684 +134
==========================================
+ Hits 6806 6952 +146
+ Misses 744 732 -12
Continue to review full report at Codecov.
|
spec/MongoTransform.spec.js
Outdated
@@ -320,6 +320,9 @@ describe('parseObjectToMongoObjectForCreate', () => { | |||
done(); | |||
}); | |||
|
|||
}); | |||
|
|||
describe_only_db('mongo')('parseObjectToMongoObjectForCreate', () => { |
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.
I was thinking about an edge to edge test case, with proper data (create multiple objects and run the query). Do you think that's possible?
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.
I was writing you to ask if this was what you where asking for. I don't know how to make this tests. Is there any edge to edge test case in the repository? Sorry, I'm not really familiar with Jasmine.
If you tell me how to make this tests or where to take an idea, I'll take a look for sure.
Do you think I should rollback this change??
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.
Do you think I should rollback this change??
You can roll it back, but that doesn't really change anything.
The edge to edge test would look like:
it('should match all strings that starts with string', (done) => {
let object = new Parse.Object('Object');
object.set('strings', ['the', 'brown', 'fox', 'jumps']);
let object2 = new Parse.Object('Object');
object2.set('strings', ['over', 'the', 'lazy', 'dog']);
Parse.Object.saveAll([object, object2]).then(() => {
return request.get({
url: Parse.serverURL + 'classes/Object',
json: true,
query: ... // build the JSON query
});
}).then((results) => {
expect(....) // TODO: validate the results
});
});
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.
thanks @flovilmart
I'll make this tests when I have some time!
I've added the tests with containsAllStartingWith function. To simplify the tests, I updated the parse dependency to the one I've implemented the containsAllStartingWith for Parse JS SDK. Sorry for the delay, but I'm so busy this days. Let me know the next steps |
@eduardbosch any chance you'd get it to work with postgres? I know that regexp support is not 💯 in PG, so perhaps you should just replace |
@eduardbosch @flovilmart I have this working for postgres. You can find a solution on my branch. You may have to add some validation on postgres transform and a few more edge to edge tests to be sure. |
Codecov Report
@@ Coverage Diff @@
## master #3864 +/- ##
==========================================
+ Coverage 92.66% 92.66% +<.01%
==========================================
Files 119 119
Lines 8585 8632 +47
==========================================
+ Hits 7955 7999 +44
- Misses 630 633 +3
Continue to review full report at Codecov.
|
7e36fb1
to
132b0d6
Compare
Thanks to @dplewis
@dplewis Thanks for the changes. I've added to the PR. @flovilmart Do you know why Travis is not checking the integration? I'm new to Travis, so I'm not really sure what's happening. I think postgres tests should work with @dplewis changes now. In the other hand, I would like to know how to add tests to check progress for regex transform. Thanks to all and sorry for the delay. I'll like to fix all this 😛 |
@eduardbosch Can you make a test for REST similar to ParseQuery.spec The following should throw an error. Every object of
|
@dplewis Now parse server checks that all values in $all must be of type {$regex: '^\Qstring\E'} or none. I've added also a REST test for containsAllStartingWith. |
package.json
Outdated
@@ -29,7 +29,7 @@ | |||
"mime": "1.3.6", | |||
"mongodb": "2.2.26", | |||
"multer": "1.3.0", | |||
"parse": "1.9.2", | |||
"parse": "eduardbosch/Parse-SDK-JS#contains-all-starting-with", |
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.
Since you are using REST the JavaScript branch isn't needed. Changing it back will remove the conflict also.
spec/ParseQuery.spec.js
Outdated
.then(function (results) { | ||
equal(results.results.length, 1); | ||
|
||
return require('request-promise').get({ |
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.
Move this to a separate test for errors
spec/ParseQuery.spec.js
Outdated
equal(objectList.length, results.length); | ||
|
||
new Parse.Query('Object') | ||
.containsAllStartingWith('strings', ['the', 'fox', 'lazy']) |
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.
REST covers this you can remove the .containsAllStartingWith
@@ -44,6 +44,30 @@ const transformObjectACL = ({ ACL, ...result }) => { | |||
|
|||
const specialQuerykeys = ['$and', '$or', '_rperm', '_wperm', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count']; | |||
|
|||
const isStartsWith = value => { |
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.
Can you move the checks from the controller to the adapters?
@@ -307,7 +307,15 @@ const buildWhereClause = ({ schema, query, index }) => { | |||
} | |||
|
|||
if (Array.isArray(fieldValue.$all) && isArrayField) { | |||
patterns.push(`array_contains_all($${index}:name, $${index + 1}::jsonb)`); | |||
if (fieldValue.$all[0].$regex) { |
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.
Here I just checked the first index but you can loop through and check all fields instead of checking on the controller
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.
The same can be done for mongo
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.
It's alredy done for Mongo too 🙂
@dplewis tests added I've added some tests to spec/MongoTransform.spec.js also. I had to setup different tests for Postgres and Mongo as containsAll works differently in both databases. Maybe would be better to try to unify the same functionality for both databases? |
} | ||
}); | ||
}) | ||
.then(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.
@eduardbosch I figured they would return different values for both databases. Some of your tests are missing .then()
return values. If you add the return values for PG I can look at the script I wrote to see if I can get similar functionality to mongo
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.
@dplewis I don't understand. Some miss .then()
return values because they throw an error, so that function is never called.
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.
Sorry missed that. Looking at your test, it should be easy to make PG throw an error instead of returning zero results for invalid $all.
…tains-all-starting-with # Conflicts: # spec/ParseQuery.spec.js
…tains-all-starting-with
$regex in $all list must be { $regex: "string" }
Sorry for the long delay! I've unified all functionality from MongoDB and PostgreSQL except when the $all array is empty. In MongoDB returns an empty result but in PostgreSQL returns all results. Maybe |
@eduardbosch @flovilmart Sorry for the late reply. The empty
Basically This should be good to merge. I'll create another PR for the empty $all |
As it stands because there’s no edge to edge tests, it’s passing but adding a proper test would let it fail. Do you believe $nor and $elemMatch would be portable to PG? |
@flovilmart Wrong thread 😜. I can look at it if there are test cases. |
Oops! Sorry!! |
@eduardbosch Sorry this took almost a year. 🎉. We learned a lot about PG and found a bug. Thanks for the contribution. 🙏 |
@flovilmart How does this look? |
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.
This is looking good if it’s looking good for you @dplewis!
Thanks @eduardbosch for your commitment and patience! |
Thanks to you @flovilmart @dplewis for your patience too!! I've learned a lot too 🎉 So happy to see this merged 😍I hope this could be a useful feature for someone. I think we should start taking a look at the SDKs integrations now:
I'm currently porting my app to iOS, so I think I'll add those changes to the iOS SDK too in a future. |
…e other given strings (parse-community#3864) * feat: Convert $regex value to RegExp object * feat: Add lib folder * Revert "feat: Add lib folder" This reverts commit c9dfbcb. * feat: Add $regex test in $all array * test: Test regex with $all only in MongoDB * Revert "test: Test regex with $all only in MongoDB" This reverts commit d7194c7. * feat: Add tests for containsAllStartingWith * feat: Add postgres support Thanks to @dplewis * feat: Check that all values in $all must be regex or none * test: Check that $all vaules must be regex or none * feat: Update tests to use only REST API * refactor: Move $all regex check to adapter * feat: Check for valid $all values in progres * refactor: Update function name * fix: Postgres $all values regex checking * fix: Check starts with as string * fix: Define contains all regex sql function * fix: Wrong value check * fix: Check valid data * fix: Check regex when there is only one value * fix: Constains all starting with string returns empty with bad params * fix: Pass correct regex value * feat: Add missing tests * feat: Add missing tests * feat: Add more tests * fix: Unify MongoDB and PostgreSQL functionality * fix: Lint checks * fix: Test broken $regex in $all list must be { $regex: "string" } * test for empty $all
Hi to all! 🎉
This changes gives support to this contributions:
parse-community/Parse-SDK-Android#673
and
parse-community/Parse-SDK-JS#437
It allows to send regular expressions with $all query.
Please, read this link to know why I need this changes in the server:
parse-community/Parse-SDK-Android#673
Thanks a lot 😀