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

#112 Adding feature to insert document when overwrite and putIfAbsent… #155

Merged
merged 5 commits into from
Feb 7, 2018

Conversation

vipulkashyap111
Copy link
Contributor

… true

@vipulkashyap111
Copy link
Contributor Author

@jasonpet @rabbah This is for #112. Added putIfAbsent flag which if set to true along with overwrite=true will do an insertion operation if the document does not already exists(404)

@rabbah
Copy link
Member

rabbah commented Feb 6, 2018

Thanks for submitting the PR. Do you have an Apache ICLA on file? https://github.com/apache/incubator-openwhisk-package-cloudant/blob/master/CONTRIBUTING.md

@rabbah
Copy link
Member

rabbah commented Feb 6, 2018

@jasonpet
Copy link
Contributor

jasonpet commented Feb 6, 2018

I can add a test and update the documentation. I will open a separate PR

Copy link
Member

@csantanapr csantanapr left a comment

Choose a reason for hiding this comment

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

Please do not add a new variable.
It's a bug if overwrite=true not working.
If overwrite=true then it should check if exists if exists then will get the rev and do an update, if it doesn't exist it should move forward and insert/write a doc.

/**
 * If id defined and overwrite is true, checks if doc exists to retrieve version
 * before insert. Else inserts.
 */

It should read to be more explicit and clear

/**
 * If id defined and overwrite is true, checks if doc exists to retrieve version
 * before insert. Else inserts a new doc.
 */

If the user action wants an error on trying to update existing doc, then don't pass the overwrite or pass overwrite=false

@vipulkashyap111
Copy link
Contributor Author

Added a new variable to provide backward compatibility. I'll update the code as per @csantanapr review comments, do @jasonpet and @rabbah agree?

@rabbah
Copy link
Member

rabbah commented Feb 6, 2018

@csantanapr I generally agree the intended behavior is to just update. The concern was about breaking existing code.

There are create and update actions which do the more conservative behavior. So we can treat this as a bug, remove the parameter and just do the update on 404. I'm OK with that too.

@jasonpet
Copy link
Contributor

jasonpet commented Feb 6, 2018

I guess only a test is needed now since we are not adding a new parameter. No annotation updates in the install script or new documentation would be necessary.

@vipulkashyap111
Copy link
Contributor Author

Removed putIfAbsent flag, document is inserted if overwrite=true and it does not already exists in the database

@@ -46,6 +46,7 @@ function main(message) {
/**
* If id defined and overwrite is true, checks if doc exists to retrieve version
* before insert. Else inserts.
* If
Copy link
Member

Choose a reason for hiding this comment

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

dangling comment.

reject(error);
if(error.statusCode === 404) {
// If document not found, insert it
return insert(cloudantDb, doc);
Copy link
Contributor

Choose a reason for hiding this comment

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

the promise that contains the cloudant "get" is never resolved for this path

Copy link
Member

Choose a reason for hiding this comment

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

good catch, looks like insert creates it own promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me update that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@rabbah
Copy link
Member

rabbah commented Feb 6, 2018

@csantanapr changes updated, can you update your review?

@rabbah rabbah dismissed csantanapr’s stale review February 7, 2018 14:08

changes made as requested.

@rabbah rabbah merged commit b1093a0 into apache:master Feb 7, 2018
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.

4 participants