-
Notifications
You must be signed in to change notification settings - Fork 16
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
Check on duplicate keys on .transactWrite()
#68
Comments
This is a good idea! I would just try to invoke the transaction. When it fails, it would be nice to provide more details on what could go wrong. AWS itself returns a So if it fails, we should try to find out why it fails. Are you trying to update the same record twice for example. |
Hi all, |
@LukvonStrom this issue still needs to be resolved. @SamVerschueren correct me if I am wrong. |
Exactly! Feel free to pick it up @LukvonStrom for hacktoberfest 2020. It was created last year for hacktoberfest but wasn't picked up. |
@SamVerschueren @SimonJang I'm proposing the following to get the duplicate keys per possible action: let actionMap = {}
for (let writeItem of this.actions) {
let keys = Object.values(item.params.ExpressionAttributeNames);
let type = "";
if (action instanceof UpdateItem) {
type = "update";
}
if (action instanceof InsertItem) {
type = "insert";
}
if (action instanceof DeleteItem) {
type = "delete";
}
if (actionMap.hasOwnProperty(type)) {
actionMap[type].keys = actionMap[type].keys.concat(keys);
} else {
actionMap.push({
type,
keys
})
}
}
for (let writeAction of Object.keys(actionMap)) {
// taken under CC BY-SA 3.0 from https://stackoverflow.com/a/35922651
let duplicates = writeAction.keys.reduce(function(acc, el, i, arr) {
if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el);
return acc;
}, []);
console.error("Duplicate key(s)", duplicates, "for", writeAction.type, "action")
} |
The transaction fails when trying to write with the same key multiple times in the same transaction. We might need to warn the user or add it as additional information when the transactions errors?
The text was updated successfully, but these errors were encountered: