tsynamo
tsynamo copied to clipboard
Transaction API bad developer experience
Currently in tsynamo:
const trx = tsynamoClient.createWriteTransaction();
trx.addItem({
Put: tsynamoClient
.putItem("myTable")
.item({ userId: "313", dataTimestamp: 1 }),
});
trx.addItem({
Update: tsynamoClient
.updateItem("myTable")
.keys({ userId: "313", dataTimestamp: 2 })
.set("tags", "=", ["a", "b", "c"]),
});
trx.addItem({
Delete: tsynamoClient.deleteItem("myTable").keys({
userId: "313",
dataTimestamp: 3,
}),
});
the term addItem is very confusing and misleading term. Even though it's what they use at the dynamo document client, I think tsynamo should drop it and name it better and less confusing.
I propose either simply:
const trx = tsynamoClient.createWriteTransaction();
trx.addStatement({
Put: tsynamoClient
.putItem("myTable")
.item({ userId: "313", dataTimestamp: 1 }),
});
trx.addStatement({
Update: tsynamoClient
.updateItem("myTable")
.keys({ userId: "313", dataTimestamp: 2 })
.set("tags", "=", ["a", "b", "c"]),
});
trx.addStatement({
Delete: tsynamoClient.deleteItem("myTable").keys({
userId: "313",
dataTimestamp: 3,
}),
});
Or:
const trx = tsynamoClient.createWriteTransaction();
trx.addPutItem({
statement: tsynamoClient
.putItem("myTable")
.item({ userId: "313", dataTimestamp: 1 }),
});
trx.addUpdateItem({
statement: tsynamoClient
.updateItem("myTable")
.keys({ userId: "313", dataTimestamp: 2 })
.set("tags", "=", ["a", "b", "c"]),
});
trx.addDeleteItem({
statement: tsynamoClient.deleteItem("myTable").keys({
userId: "313",
dataTimestamp: 3,
}),
});
What do you think?
Thanks for opening an issue! I agree that the naming could be better, albeit, as you say, that's the name they also use in the actual DynamoDB client. I like the addStatement, but then, on the other hand, I would be "making up" terms that do not exist in DynamoDB, which might also cause confusion. Perhaps the addPutItem, addUpdateItem, and addDeleteItem is the way to go!