Is there a way to do multiple storage operations in a single transaction? For instance, if I want to do a storage write and storage delete in an atomic manner (so that if one fails, the other is rolled back), is there a way to do this? Of course, I could use the SQL API directly, but I am hoping that Nakama’s runtime API provides high level facilities for doing this for me.
@jonbonazza There’s no way to do a delete and a write/update as an atomic operation but its possible to do multiple writes (batched) as a single atomic operation. What use case do you have where you’d want to delete an object while you write another?
When a player completes a quest, I want to update the state of the quest for that player to be completed and also delete a flag that was set previously that marked the quest as accepted.
I guess i could have a reaper goroutine that runs periodically and cleans up the flags, but yea… Would be nice to be able to ensure atomicity at the storage level.
Actually, the reaper idea wouldnt work because i rely on that accepted flag for validating quest acceptance and for repeatable quests, i need to ensure that flag is gone.
@jonbonazza Why use two different keys to represent the “accepted” and “completed” states? If the quest is marked with a timestamp (non-zero) value it must have been accepted and now has transitioned to completed?
You could even use -1 as a sentinel value on the “timestamp” to indicate whether its transitioned from available to accepted. This would eliminate the second field that needs to be later deleted entirely. What do you think?
That’s… Actually a fair point an im a little embarrassed I didnt consider that.
No worries. All good