Skip to content

Add basic json query support #304

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

Merged
merged 1 commit into from
Nov 2, 2017

Conversation

zbarbuto
Copy link
Contributor

Description

Add basic support for json querying (where and order-by only - no field limiting to keep it simple).

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

Incidentally, I notice this repo doesn't support ES6 syntax online some of the other loopback repos now do 😞

@zbarbuto
Copy link
Contributor Author

@slnode test please

Copy link
Contributor

@b-admike b-admike left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Really good patch, complete with docs and tests. I've left a few comments.

@@ -321,6 +321,30 @@ function escapeLiteral(str) {
return escaped;
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add JSDocs here for the property param?

return property.split('.').length > 1;
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

JSDocs would be great here as well.

// Unknown property, ignore it
debug('Unknown property %s is skipped for model %s', key, model);
continue;
if (isNested(key)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would p be null if the property has nested json keys? In other words, could we move this condition outside of the p == null check? I'm worried that this is unreachable code, unless I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

p can be null if the property is not defined on the model. Model might have foo property but foo.bar is being queried so props[key] is null but isNested(key) is true.

On the flip side if we try to query baz (which doesn't exist on the model and isn't a nested query) it should fall through so nothing unreachable.

However you do make a point that p could be null if it is nested and the property doesn't exist on the model. Will fix that.

db.automigrate(function(err) {
if (err) return done(err);
Customer.create([{
address: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add test/s for 1 more level of nested keys (for checking the recursive calls in https://github.com/strongloop/loopback-connector-postgresql/pull/304/files#diff-ac54005f9bbf753aa45ceebc4a032628R341, or would that be redundant? I.e.

Customer.create([{
  name: {
    fullName: {
      firstName: 'foo'
      lastName: 'bar'
    }
  }
}], function (err, customers) {
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely not redundant since it uncovered a bug 😅

Syntax for deeply nested needed to be foo->bar->>baz since ->> returns the value at the path as text but -> returns the actual object at the path.

https://www.postgresql.org/docs/9.5/static/functions-json.html

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah great! thank you for the link :-).

@zbarbuto
Copy link
Contributor Author

@slnode test please

@zbarbuto
Copy link
Contributor Author

Unable to see failures due to IBM firewall - but tests were passing locally and seem to be failing in other pull requests so possibly unrelated.

@b-admike
Copy link
Contributor

@slnode test please

Copy link
Contributor

@b-admike b-admike left a comment

Choose a reason for hiding this comment

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

🚢🇮🇹

@b-admike
Copy link
Contributor

@slnode test please

@b-admike
Copy link
Contributor

b-admike commented Oct 31, 2017

@zbarbuto It was failing for the following reason:

> [email protected] test /home/jenkins/workspace/nb/loopback-connector-postgresql~master/504599fa
> mocha -R spec --timeout 10000 --require test/init.js test/*.test.js

module.js:471
    throw err;
    ^

Error: Cannot find module 'pseudomap'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/jenkins/workspace/nb/loopback-connector-postgresql~master/504599fa/node_modules/lru-cache/index.js:7:11)
    at Module._compile (module.js:570:32)

although I don't see that module used here. I've kicked off another build.

@zbarbuto
Copy link
Contributor Author

Correct, that wasn't added as part of this PR.

Apparently there were some issues with the internal registry recently - probably related

loopbackio/loopback-datasource-juggler#1513

@b-admike
Copy link
Contributor

b-admike commented Nov 2, 2017

@zbarbuto all the tests are passing now 🎉. Please squash your commits into one since they're all for one logical change, and we should be able to land.

@zbarbuto
Copy link
Contributor Author

zbarbuto commented Nov 2, 2017

Squished

@b-admike b-admike added this to the Sprint 48 milestone Nov 2, 2017
@b-admike b-admike self-assigned this Nov 2, 2017
@b-admike
Copy link
Contributor

b-admike commented Nov 2, 2017

Thanks @zbarbuto!

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

Successfully merging this pull request may close these issues.

3 participants