Created
August 17, 2020 03:48
-
-
Save bibhuticoder/8f37c06482b550279c27d35e55f3df06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// automatically appends updatedAt timestamp | |
const update = async (updateParams) => { | |
try { | |
const timestamp = new Date().getTime(); | |
params.UpdateExpression = params.UpdateExpression + ', #updatedAt = :updatedAt'; | |
params.ExpressionAttributeNames['#updatedAt'] = 'updatedAt'; | |
params.ExpressionAttributeValues[':updatedAt'] = timestamp; | |
return await db.update(updateParams).promise(); | |
} | |
catch (error) { throw error; } | |
}; | |
var params = { | |
TableName: 'PRODUCTS_TABLE', | |
Key: { "id": someProductId }, | |
ConditionExpression: 'id = :id AND createdBy = :createdBy', | |
UpdateExpression: 'set #data.#price = :updatedPrice', | |
ExpressionAttributeNames: { '#data': 'data', '#price': 'price' }, | |
ExpressionAttributeValues: { ':id': someProductId, ':updatedPrice': 3456.78, ':createdBy': creatorId } | |
}; | |
try { | |
await dynamoDB.update(params); | |
} catch (error) { | |
console.log(error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment