Skip to content

beyonce.batchWriteWithTransaction with Updates #64

@e-nouri

Description

@e-nouri

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions