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

Add .ignoreConditionalCheckFailed to WriteRequest #310

Open
jthomerson opened this issue Jun 4, 2020 · 0 comments
Open

Add .ignoreConditionalCheckFailed to WriteRequest #310

jthomerson opened this issue Jun 4, 2020 · 0 comments

Comments

@jthomerson
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Often when doing updates, you need to prevent against upserts with something like update.onlyIfAttribute('pk').attributeExists(). It often is not really a failure when the condition fails; it just means "there was no item there to update". You then have to catch the error that DynamoDB throws and ignore the ConditionalCheckFailedException.

Describe the solution you'd like
I'd like to be able to do this:

await store.update(file.pk, file.sk)
   .updateAttribute('filename').set(newValue)
   .onlyIfAttribute('pk').attributeExists() // but don't allow upserts
   .ignoreConditionalCheckFailed() // if there's no item there, that's fine
   .exec();

Describe alternatives you've considered
I currently have a reusable catch function that I use:

export default function ignoreConditionalCheckFailedException(err: any): void {
   if (err && err.code !== 'ConditionalCheckFailedException') {
      throw err;
   }
}

await update.exec().catch(ignoreConditionalCheckFailedException);
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

No branches or pull requests

1 participant