upsertWithWhere method - #1001
Conversation
|
@raymondfeng @Amir-61 : Please consider this pull request. I believe following things are pending from the merge : !) Test case addition 2) All tests passing Please let me know if anything else is pending for the merge to happen. I have already started to write the tests. Should be able to commit by tomorrow. Also, I have already signed the CLA and when I click on details, it says you have signed the CLA. I was wondering why is it saying not all contributors have signed the CLA. This is a fresh fork with a fresh commit and a new pull request. Reference : I have incorporated the following review comments from @raymondfeng and @Amir-61 :
@Amir-61 I wanted to get these changes merged soon since we have a blocking , high priority requirement. Request your support and guidance in doing the same. |
|
Follow up from : #995 |
|
I'm confused why creating another PR, while you had another open PR#995. So IIUC you are making the scope of this work smaller by proposing to skip the |
|
@Amir-61 |
It's important to provide an atomic implementation in the memory connector. The current implementation, which executes multiple database commands, is prone to race conditions. (Consider what happens when two requests to upsert the same record are handled at the same time in parallel.)
The promise of operation hooks is that regardless of the operation invoked, the hook observers will be always executed. I.e. if a user installs "before save" observer, they can be confident their handler will be always invoked before any change is being persisted. I am not comfortable breaking that promise. I would much rather see operation hooks implemented in as part of this patch. It's ok to keep this work incremental though. You can continue adding unit-tests for the functionality already there, and leave implementation of operation hooks only after the other known issues are resolved. |
| . This is a PUT operation and based on | ||
| * non-primary key. The filter takes one key value pair and updates single matching instance.* | ||
| */ | ||
| DataAccessObject.upsertWithWhere = function(where, data, options, cb) { |
There was a problem hiding this comment.
In longer term, we want to promote patchOrCreate instead of upsert/updateOrCreate. Can you please add an alias patchOrCreateWithWhere = upsertWithWhere? See how other aliases in this file are set up.
|
@bajtos |
|
@slnode ok to test |
|
@bajtos .. one clarification.. so will it be ok to merge after resolving the comments you have suggested to the current implementation and along with unit tests passing. And then incrementally add on these operation hooks soon after the first merge. Or, do we need to have everything together for the first merge. |
I would prefer to have everything together for the first merge. |
|
@bajtos
|
|
@bajtos |
|
|
||
| var pk = idName(Model); | ||
| if (keys[0] !== pk) return false; | ||
|
|
There was a problem hiding this comment.
unrelated change, please remove. same applies for the removed line above.
3ec1f5e to
1cfddb6
Compare
|
@Amir-61 I have squashed all commits into one now and rebased on top of master. |
| hookState: ctx.hookState, | ||
| options: options, | ||
| }; | ||
| Model.notifyObserversOf('loaded', contxt, function(err) { |
There was a problem hiding this comment.
ummm not sure why you could not use context as opposed to contxt; probably it conflicts the name. How about using ctx instead of contxt which is missing e
There was a problem hiding this comment.
we are making use of ctx.hookstate , which is defined before we define the context properties for 'loaded'. Using ctx instead will make ctx.hookState undefined. Hence, I have left the variable name as contxt .
Thanks! I left a few minor comments which should be pretty easy to address; the code looks almost good to me. I leave the final approval to @bajtos. @superkhau also you may look into this patch as well before @bajtos goes for final approval. |
|
@raymondfeng @bajtos I've looked at this PR enough and I am about as confident as I can be. Gonna need your opinions here for final LGTM. |
|
LGTM from my side after addressing my minor comments. Final LGTM needs to be either from @bajtos or @raymondfeng |
|
I took a quick look and did not see any obvious problems. Let's get this landed, we can always fix bugs later when they are discovered by a real user. |
1cfddb6 to
37541dd
Compare
|
@mountain1234585 Thanks for the contribution! I landed it! 🚢 |
|
I will back-port it |
|
Thankyou @Amir-61 @bajtos @superkhau @rmg @raymondfeng : For your valuable feedback and the reviews on this PR. I had a great learning ! |
|
Backport PR #1052 |
No problem. My pleasure! |
Added a new method for performing upsertWithWhere in dao.js
Connect to strongloop/loopback#2331
Connect to strongloop/loopback#2539