Got a question for a SSS/Function. I want to creat...
# prisma-whats-new
h
Got a question for a SSS/Function. I want to create a new statistics-entry if the user has none yet, or update the exisiting row if he/she does. The playground lets me know there’s an “updateOrCreateWidgetData” type, but I”m unsure how it works? Any way I can look for exisiting entries in the subscription query and pass the ID along to my function?
m
Is this triggered by some kind of user action?
h
Yes, create/delete/update a journal
I do statistics calculations for the user based on his/her journals, and create a row called “widgetData”
I want the function that runs when the subscription fires to be able to either create a new row for the user if the user has no rows yet, or update the exisiting row if he does
So I’m interested in the id of a potentially exisiting row beeing passed on to mu function from the subscription payload
m
You could run a query from inside the function that checks for existing rows
h
Sure, but that leads to an extra request towards the monthly rate, and also more latency for the calculation 🙂
Also another link in the chain of events that can fail
m
True. You could include that widgetData as part of the query, and it should be included as part of the payload.
It would return all widgetData rows though, if more than one existed
h
Ah, I think I can. I can just ask for references to the widget data table on the user - if none exists, I’ll create, otherwise I’ll update!
👍 1