Hello just a quick question. Is it
# spicedb
j
Hello just a quick question. Is it possible to check in a Precondition of WriteRelationshipRequest if there would be any relationship left if i would delete it ?
v
What's the use-case? Unless you need to write and delete at the same time, and you need the delete to really happen in a single transaction, I'd suggest you look into
DeleteRelationships
, which will tell you in the response if there are any more relationships to delete when you specify a limit. Othewise you could check after the transaction takes place:
WriteRelationships
will give you a zedtoken, and so you could then issue
ReadRelationships
at the specified token, which would give you the state of the system when the write took place.
j
Thank you. I think I just have to do the check afterwards and roll back if necessary.
I was wondering if there was a possibility to check the left amount of a specific kind of relationship before I make a write request. So the lookup and the write would be one Request/Transaction
Maybe not possible
The use case was to demote a supervisor only if there would be one left afterwards
v
I think the solution is simple in this case. You read one supervisor that is not the one about to be deleted. Then you proceed with a
WriteRelationships
that has a precondition "this supervisor must exist before proceeding". If the precondition fails, then you know some other transaction deleted a supervisor, so all you have to do is retry again.
j
Genius anwer and thread safe. Thank you
33 Views