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

Fix issue #49 - $where operator is not evaluated last #50

Merged
merged 3 commits into from
Jun 22, 2017

Conversation

lackofbrilliance
Copy link
Contributor

This change stores off any $where operators encountered in the _compile function, and then calls _processOperator on each after _processOperator is called for other operators.

This change stores off any $where operators encountered in the _compile function, and then calls _processOperator on each after _processOperator is called for other operators.
Copy link
Owner

@kofrasa kofrasa left a comment

Choose a reason for hiding this comment

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

Some minor feedback for simplicity and consistency

mingo.js Outdated
@@ -1342,6 +1348,11 @@ Mingo.Query.prototype = {
}
}
}
var self = this;
console.log(whereOperators);
Copy link
Owner

Choose a reason for hiding this comment

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

Remove debug statement

mingo.js Outdated
if (inArray(['$where'], field)) {
whereOperators.push({field: field, expr: expr});
}
else if (inArray(['$and', '$or', '$nor'], field)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Prefer the style

if (<condition>) {
  <statements>
} else if (<codition2>) {
...

mingo.js Outdated
for (var field in this.__criteria) {
if (has(this.__criteria, field)) {
var expr = this.__criteria[field]
if (inArray(['$and', '$or', '$nor', '$where'], field)) {
// save $where operators to be executed after other operators
if (inArray(['$where'], field)) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think an equality check will do here. '$where' === field

mingo.js Outdated
@@ -1327,10 +1327,16 @@ Mingo.Query.prototype = {

assert(isObject(this.__criteria), 'Criteria must be of type Object')

var whereOperators = [];
Copy link
Owner

Choose a reason for hiding this comment

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

Only one $where expression allowed in query so this can be single valued

Copy link
Owner

@kofrasa kofrasa left a comment

Choose a reason for hiding this comment

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

I am happy with the updates though I must apologize for not spotting earlier that you worked on the wrong file.

Development happens on modularized files in the lib/ folder and the make script builds the mingo.js file. The correct file to edit is https://github.com/kofrasa/mingo/blob/development/lib/query.js.

Then you can run the command make mingo.js to amalgamate and then make test to run the unit tests. This one is on me, but I will appreciate if you made the final update.

Thanks for the good work done so far.

@lackofbrilliance
Copy link
Contributor Author

No worries, I should have caught that mingo.js is built from all of the files in lib.

@kofrasa kofrasa merged commit 15dcf61 into kofrasa:development Jun 22, 2017
@kofrasa
Copy link
Owner

kofrasa commented Jun 22, 2017

Thanks for your contribution.

@lackofbrilliance lackofbrilliance deleted the issue-49 branch June 23, 2017 14:38
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.

2 participants