I am having trouble trying to figure out some queries with data blaze.
My goal is to see if a row exists, and if it does, just update the row. If it doesn't, then insert a new row. I have 2 scenarios which I have tried but the documentation is lacking on a few elements or I am just missing it.
My first try was to read the db to see if a row exists, and if it doesn't, then insert a new row, if it does, then update. This works, but I dont need or want a form to pop up on the read. I just want to pass if the SELECT was successful or not (or if the row exists), and use it as a condition to decide the next action.
(this are simplified for the post)
{id={clipboard}}
{dbselect: SELECT user_id FROM Userlist WHERE user_id = @user_id; space=1Sh7eQMLS3dHzazQFwCYsU; menu=no; trim=yes; haserror=error}
{if: error}
// no row exists: Insert New Row
{else}
// row exists: Update Existing Row
{endif}
I really dont care for the popup form on the Select since I only ever do 1 at a time and i specifically copy the id right before hand to pull or update information.
The other method I tried because I don't want the form to pop up is to just try and update a row, and if it fails, to insert instead.
{user_id="7587504885"; trim=yes}
{user_name="Danner"; trim=yes}
// I want to try to update first
{dbupdate: UPDATE Userlist
SET user_name=@user_name
WHERE user_id = @user_id; space=1Sh7eQMLS3dHzazQFwCYsU; autoaddfields=no; trim=yes; completed=(res, status) -> "ERROR" if res <> 200 else ""}
// Then insert if it fails.
{if: error} <--I need to catch the result to go here on if the update was a success or not.
// row doesn't exist: Insert New Row
{endif: trim=yes}
I just have no idea how to grab the result or status of if this update query completed. I tried iserror(), catch(), . This method doesn't bring up a form which I like, but I can't figure out how to use "completed" properly nor find documentation for it that has examples of proper use.
Can someone help me figure this out? Or point me towards another solution? I rather not have the for popup if at all possible from the read, so I prefer the second option. I appreciate any guidance here!