How can I handle ID collisions
I know that it is very unlikely for an id collision to happen but I would like to know possible ways to handle it. Is there an easy way that I can do that in drizzle?
7 Replies
uuid ? e.e
Yes UUID is a choice but it's too large and takes too much space - compared to nanoid for example.
ok
Hi there. Drizzle doesn't provide any way to handle those collisions, you have to handle them yourself
Ideally, it shouldn't even happen in the first place, but if you're really worried about a collision happening, you could write your own abstraction to handle it
Alright. Thank you
just use built in crypto.randomUUID()
its built in
I would also use UUID. Yes, it takes more space but the chances of getting collision are absurdly low. In this case as the collision probability is so low I would just send an error to the client and let the user repeat the action. If you are using multiple PUT, DELETE; POST operations in the same server/API call make sure to use Drizzle transactions so you don't need to undo anything manually in case of collision.