-
Notifications
You must be signed in to change notification settings - Fork 362
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
Ability to define normalization of undefined query #725
Ability to define normalization of undefined query #725
Conversation
Add setting to datasource `normalizeUndefinedInQuery` to determine how it will handle undefined values. Options: - setNull : converts undefined to null - throwError : throw an error on undefined value - strip : strip the key where undefined value is found Defualt operation is to strip the key.
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
@slnode ok to test |
Hi @jrschumacher, thank you for the patch! I would personally prefer different option names.
Few more ideas to consider:
I'm fine to leave those two out of scope of this PR though. |
@raymondfeng since you are more familiar with the issue being fixed, I'd like to leave review & approval for you to make. |
@bajtos I'm happy to change the naming. Will fix later today also I'll look into exploring the model level settings. Questions regarding that: if you set data source level should model level overwrite? Is there an order of precedence? |
@bajtos regarding the persistUndefinedToNull would it be better to change the datasource setting name to be similar in naming? Or does persist refer more to the longevity of the data in the datasource rather than the transient query? |
Here is my take:
|
@raymondfeng got it |
@raymondfeng I think the connector level will be valuable to MongoDB users. So maybe if you have a RDBM or redis datasource you will want the stripping effect but with MongoDB the stripping created some serious issues. |
👍 for @raymondfeng proposal.
Yes, more-specific level should override less-specific level. I.e. model level overrides datasource level.
You name is fine. |
@raymondfeng @bajtos could I get some help on how to fetch the app settings? I've created a method to get settings based on priority but need to add app settings: https://github.com/strongloop/loopback-datasource-juggler/pull/725/files#diff-d717a01e40d8164976e4468af1bce663R942 |
this.app.get('propName') should work |
@raymondfeng I've done this, but I don't know how to add the tests for this. There doesn't seem to be a global |
I'd rather not use |
Another approach is to override datasource settings when creating a new datasource in an app - see https://github.com/strongloop/loopback/blob/e68cd8fc87730404a78e1475b828886e3582bd6f/lib/application.js#L221-L227 |
@bajtos then is there anything else that's needed from me here? I'm not sure why the above tests fail. Locally all the tests pass. |
Hmm, the tests are failing with this error:
Could you please rebase your feature branch on top of the current master and run the tests locally again? |
return ds.settings[key]; | ||
} | ||
|
||
// @TODO: Check for settings in app |
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.
Please remove per the conversation above.
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.
@bajtos am I just removing the TODO or all of it?
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.
Just the TODO. It would be nice if you could send a patch to LoopBack which will apply app settings to newly created datasources, but that's not necessary to get this patch landed.
@bajtos yep I'll rebase. Regarding the settings. Shall I still get model and datasource but do it in the normalize method? |
Your current approach LGTM, I left few mostly stylistic comments to address. |
Added method to get settings based on priority
ef43a73
to
5c40e48
Compare
@bajtos okay I think I handled all the issues you mentioned. |
I'll consider this, but its not going to be anytime soon. Also I took note of the references you mentioned, but I have to say I'm a bit at a loss exactly what you're asking me to do. Is this specific to this setting or is it for all settings? |
Landed via 98fb3c6, thank you for the contribution!
I'd modify app.datasource() to apply this specific setting only. |
Released as |
Glad to help! On Oct 7, 2015, 16:01 -0400, Miroslav Bajtoš[email protected], wrote:
|
Add setting to datasource
normalizeUndefinedInQuery
to determine howit will handle undefined values. Options:
Defualt operation is to strip the key.