-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdateInApplication.js
More file actions
36 lines (34 loc) · 914 Bytes
/
updateInApplication.js
File metadata and controls
36 lines (34 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
docClient.get({
"TableName": "counters",
"Key": {
"counterName": "importantCounter"
},
"ConsistentRead": true
}, function (err, data) {
if (err) console.log(err);
else {
const currentValue = data.Item.currentValue;
const newValue = currentValue + 1;
docClient.update({
"TableName": "counters",
"ReturnValues": "UPDATED_NEW",
"ExpressionAttributeValues": {
":a": currentValue,
":bb": newValue
},
"ExpressionAttributeNames": {
"#currentValue": "currentValue"
},
"ConditionExpression": "(#currentValue = :a)",
"UpdateExpression": "SET #currentValue = :bb",
"Key": {
"counterName": "importantCounter"
}
}, function (err, data) {
if (err) console.log(err);
else console.log(data);
})
}
});