AshObjectIds
https://hex.pm/packages/ash_object_ids
An Ash implementation of the "Stripe IDs" (human readable, copyable, IDs with a prefix for the model they reference): https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a
TLDR:
Externally, these are prefixed, base58-encoded UUIDs.
15 Replies
Nice! Don't forget to add a link to the project 😄
Haha, you're right, forgot the most important part. Added it.
The only thing I wasn't sure about with this library was the use of persisters to generate the type module for each resource
What would it look like to migrate from using plain UUIDs to AshObjectIds?
I did think about adding some kind of "allow raw uuids" option to provide an upgrade path. But I primarly made this lib for greenfield projects, so I hadn't added it yet
The absence of a
_
character in the ID should be a giveaway that it isn't an Object ID.
Of course, you still need to disambiguate Object IDs that have been orphaned from their prefix vs raw UUIDs, but luckily they are encoded differently.Yeah it shouldn't be a lot of work; it's just work I haven't done 😛
Hi! This is great, thanks!
A nitpick about the name though: it can be confusing. At least in my experience, people who know about databases usually identify "objectId" with MongoDB's
_id
s. If this is only for Stripe IDs, it should be easily recognizable by its name. Same thing if it is a generic package for several types of unique identifiers.
I read the article though, and they themselves call it both ways so I don't even know lolAh, I see they are stored as UUID, so theoretically, one could switch to using these without changing the database
Yes they're stored as plain UUIDs. I believe stripe actually stores them encoded and all, but I have a use case where I want to keep them UUIDv7 in the database.
What benefit is there of storing as UUIDv7 in the database? Timestamp extraction?
Sorting & cursor-based pagination
Hexdocs link from hex is broken @Randall
Fixed, thanks
@Randall I'm putting this in the ash weekly news letter, do you want me to use your full name?
Publishing for now but happy to edit as you like later 🙂
It's fine like this