curious if people prefix their IDs in their databa...
# random
t
curious if people prefix their IDs in their database or API, eg
Copy code
usr-<ulid/uuid>
a
Personally I haven’t (yet) but I see the pattern in Stripe API’s so I’ve actually been thinking how it would fit and what would be the use cases
g
I'm using usr_${ulid().toLowercase()}
a
have you found any advantages using prefixed ids as opposed to regular ulid() ? I guess in something like a single table design in dynamodb it's good but I can't really see the need in e.g. sql
g
yes it is very useful especially during debugging and also for no-tech-people (business team or customers) which they could have e reference to understand if the id you ask is what they are sending you.
a
hmm that sounds fair. are you using this lib or is there anything more up to date?
g
I'm using that library
t
Do you do it in the API or in the database also
g
also in database, but I usually keep items with same type in a single partition to keep things sorted
j
Yep, I've just started using that pattern for a side project. Mostly because of Stripe too. It has made it much simpler when debugging to just know what is that an id of without having to go get the item first. I do it on the database level, so I have a Table Class that accepts the prefix and automatically puts it in. For every operation. One thing I changed is that I used a 4-letter prefix. As it's more easily understandable for the entity type names for my use case.
j
Here is a library for fairly customizable, Stripe-like, sortable IDs : https://www.npmjs.com/package/flexid