Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction API bad developer experience #30

Open
sasumaki opened this issue Jun 3, 2024 · 1 comment
Open

Transaction API bad developer experience #30

sasumaki opened this issue Jun 3, 2024 · 1 comment

Comments

@sasumaki
Copy link
Contributor

sasumaki commented Jun 3, 2024

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?

@woltsu
Copy link
Owner

woltsu commented Jun 4, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants