This post got longer than I intended, but early on when we switched to Dynamo, we couldn't get much help. I don't think many people here use it honestly, or they don't have questions about it. I thought I would throw a little extra into my response. You can use these actual working queries to troubleshoot your issues. NoSQL Workbench was a huge help to us getting Dynamo to work with Retool.
I highly suggest storing these types of queries in a regular JavaScript query and calling them dynamically. This approach cuts down on resources and makes troubleshooting and ordering queries much easier.
For example, my "Put" or "Update" actions are all in one DynamoDB query called "singlePut", and I point a temporary state at it, changing the temp state to whatever query I'm running.
Inside the standard query, I have a switch statement that looks at a temp state that I set before triggering the query based on which button or action is triggering the query. So, when I click the button, it sets the putOption
temp state to one of the cases contained in the below code and runs whichever case is needed based on the button press. The first case is an error if somehow the temp state didn't get set, which I added after failing to set the temp state during early testing and getting so frustrated that I added that in so if I forgot again, I wouldn't spend so much time troubleshooting.
switch (putOption.value) {
////////////////////////////////////////////////
case "": utils.showNotification({title:"Something went wrong, contact support",description:"ERR#2DPQ",notificationType:"info"})
break;
////////////////////////////////////////////////
case "newDiscussion":
var discussionUUID = uuid.v4()
await putOption.setValue(
{
TableName:"TABLE_NAME",
Item:{
PK:"Discussion#"+discussionUUID,
SK:"Discussion#"+discussionUUID,
subject:textInput3.value,
linked:checkbox1.value,
users:multiselect1.value,
latestMessage:textArea1.value,
latestUser:current_user.email,
searchSK:new Date(),
searchPK:"Discussion",
gsi1PK:false,
gsi1SK:select1.value
}})
await singlePut.trigger()
await selectedDiscussion.setValue("Discussion#"+discussionUUID)
await putOption.setValue("newMessage")
console.log("Put Option set to "+putOption.value)
putQuerys.trigger()
console.log("Recusion")
getDiscussions.trigger()
break;
////////////////////////////////////////////////
case "newMessage":
console.log("Recursion Success")
console.log(selectedDiscussion.value)
await putOption.setValue(
{
TableName:"TABLE_NAME",
Item:{
PK:selectedDiscussion.value,
SK:"Message#"+uuid.v4(),
user:current_user.fullName,
message:textArea1.value,
linkedItem:newMessagePDFPreview.value,
image:newMessageImagePreview.value,
searchPK:selectedDiscussion.value,
searchSK:new Date()
}})
singlePut.trigger()
textInput3.clearValue()
select1.clearValue()
multiselect1.clearValue()
textArea1.clearValue()
console.log("Message followed up")
console.log(putOption.value)
getSelectedDiscussion.trigger()
break;
/////////////////////////////////////////////
case "soloMessage":
console.log("Solo Message")
await putOption.setValue(
{
TableName:"TABLE_NAME",
Item:{
PK:selectedDiscussion.value,
SK:"Message#"+uuid.v4(),
user:current_user.fullName,
message:textInput4.value,
linkedItem:newMessagePDFPreview.value,
image:newMessageImagePreview.value,
searchPK:selectedDiscussion.value,
searchSK:new Date()
}})
await singlePut.trigger()
textInput4.clearValue()
newMessageImagePreview.setValue("")
newMessagePDFPreview.setValue("")
console.log("Solo Message Done")
getSelectedDiscussion.trigger()
break;
}
This might not be the best way to handle any of this, but I've found it very useful for being able to test our code. The above are just standard puts into our DynamoDB, but below is an update query that doesn’t use the visual parameters.
{
"TableName": "TABLE_NAME",
"Key": {
"PK":"project#001",
"SK":"openings"
},
"UpdateExpression": "SET #doorTypes.#type =if_not_exists(#doorTypes.#type,:type)",
"ExpressionAttributeValues": { ":type": {{transPutDT.value.putObj}} },
"ExpressionAttributeNames": {"#doorTypes": "doorTypes","#type":{{tiDoorType.value}} },
}
You can see from the above you can also drill down into objects this way, probably would work in the visual parameter version also, but it's easier this way, I think.
I highly suggest downloading the NoSQL workbench and connecting to your Dynamo instance; you can design queries in the operation builder and output them into Python. It isn’t perfect, but it gives you a great starting point on a very complicated update.
You basically just need to remove the "S" in the ExpressionAttributeValues portion or anywhere where it tries to define a specific value type.
GOOD LUCK!
PS: This was from an early test, my code is much prettier than that first block now. I apologize if its hard to read hahaha.