Persistent comes with two operations for wholesale replacement of records: replace
and repsert
. With repsert
, a new record is inserted into the database if the record to be replaced did not originally exist. With replace
, if the record to be replaced does not exist, the behavior is undefined.
Both of these options are insufficient for my use-case: I want to replace a record if (and only if) a record already exists for that key. I could check if the record exists first and only attempt an insertion if this returns a record, but this seems like it would have the potential for race conditions (though admittedly such race conditions would be unlikely to have harmful effects in this case).
Is there any function that attempts to do a replacement and returns a useful result depending on success or failure?