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
edarcode
edarcode4mo ago
uuid ? e.e
Δάρκζυ
ΔάρκζυOP4mo ago
Yes UUID is a choice but it's too large and takes too much space - compared to nanoid for example.
edarcode
edarcode4mo ago
ok
Mario564
Mario5644mo ago
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
Δάρκζυ
ΔάρκζυOP4mo ago
Alright. Thank you
iska
iska4mo ago
just use built in crypto.randomUUID() its built in
marcbejar
marcbejar4mo ago
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.
Want results from more Discord servers?
Add your server