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

Increment value in DynamoDB table #71

Open
lorenzocastelli opened this issue Jun 19, 2020 · 1 comment
Open

Increment value in DynamoDB table #71

lorenzocastelli opened this issue Jun 19, 2020 · 1 comment

Comments

@lorenzocastelli
Copy link

Hi! Thanks for the library! I've a question: Is it possible to update an item stored in the dynamoDB table incrementing a value without read it, update the value and finally write again.

Using the aws-sdk you can do something like it:
dynamoDB.updateItem({ TableName: "Users", Key: { "UserId": { S: "c6af9ac6-7b61" } }, ExpressionAttributeValues: { ":inc": {N: "1"} }, UpdateExpression: "ADD loginCount :inc" })
Thanks!

@mooyoul
Copy link
Contributor

mooyoul commented Jun 19, 2020

You can use update query to increment attribute value:
(To decrement value, Simply supply negative value)

// for HashPrimaryKey based Table
Table.primaryKey.update(hashKey, { attr: ["ADD", 1] }); // equivalent to "ADD attr 1"
// for FullPrimaryKey based Table
Table.primaryKey.update(hashKey, rangeKey, { attr: ["ADD", 1] }); // equivalent to "ADD attr 1"

FYI, All of maintainers of dynamo-types left Vingle, Inc. (which is owner of this repository.) Unfortunately, We couldn't get permissions from Company - We lost all permissions about this repository (including access credentials for accessing NPM).

So, We've forked this repo to serverless-seoul/dynamorm.

We won't make any further updates on this repository. Please leave an issue to forked repository if you have further questions. Thanks.

cc/ @breath103

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

2 participants