-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Is there a way to do batch write with updates, puts and deletes ?
I think I red on the doc that conditional updates are not yet possible to ?!
Right now I am using the dynamodb client to make something like this work :
client.transactWrite({
TransactItems : [
{
"Put": {
"TableName": `${process.env.DATA_TABLE}`,
"Item": {
"pk": {"S": `${BeginsWith.User}-${userId}`},
"sk": {"S": `${BeginsWith.Friend}-${firendId}`},
"followedUser": {"S": userId},
"followingUser": {"S": firendId},
"timestamp": {"S": +new Date},
},
"ConditionExpression": "attribute_not_exists(sk)",
"ReturnValuesOnConditionCheckFailure": "ALL_OLD",
}
},
{
"Update": {
"TableName": `${process.env.DATA_TABLE}`,
"Key": {"pk": {"S": `${BeginsWith.User}-${firendId}`}, "sk": {"S": `${BeginsWith.User}-${firendId}`}},
"UpdateExpression": "SET followers = followers + :i",
"ExpressionAttributeValues": {":i": {"N": "1"}},
"ReturnValuesOnConditionCheckFailure": "ALL_OLD",
}
},
{
"Update": {
"TableName": `${process.env.DATA_TABLE}`,
"Key": {"pk": {"S": `${BeginsWith.User}-${userId}`}, "sk": {"S": `${BeginsWith.User}-${userId}`}},
"UpdateExpression": "SET following = following + :i",
"ExpressionAttributeValues": {":i": {"N": "1"}},
"ReturnValuesOnConditionCheckFailure": "ALL_OLD",
}
},
]
})
Thank you so much again for this library, Beyonce rocks !
Metadata
Metadata
Assignees
Labels
No labels