Re:Sqids – Generate Short Unique IDs from Numbers
by Bytewave81 on Saturday November 25, 2023 @03:44PM
(#38416524)
The idea is that you encode and decode database IDs with this. You wouldn't save them separately unless you were using it for a purpose other than shareable "identifiers" which don't leak significant amounts of database state. Imagine something like a link shortener where you want to provide a short link to users, but don't want it to just be a number.
Re:Sqids – Generate Short Unique IDs from Numbers
by ComputerGuru on Monday November 27, 2023 @09:46AM
(#38432790)
My point was that this only encodes numbers and you wouldn’t use numbers as primary keys for the reasons outlined.
Re:Sqids – Generate Short Unique IDs from Numbers
by hot_gril on Monday November 27, 2023 @10:11PM
(#38441829)
These leak the state just as much. They're reversible back to integers.
Re:Sqids – Generate Short Unique IDs from Numbers
by swyx on Saturday November 25, 2023 @04:45PM
(#38416992)
why is ulid the uuidv7 of tomorrow?
Re:Sqids – Generate Short Unique IDs from Numbers
by ComputerGuru on Monday November 27, 2023 @09:46AM
(#38432794)
Uuidv7 is inspired by ulid.
Re:Sqids – Generate Short Unique IDs from Numbers
by canadiantim on Saturday November 25, 2023 @06:22PM
(#38417710)
I’m currently using sqids as slugs to have a shorter url than just using my uuid primary key
Re:Sqids – Generate Short Unique IDs from Numbers
by ComputerGuru on Monday November 27, 2023 @09:47AM
(#38432807)
Why would the number the sqid converts to not be your primary key, though? Why do you need the uuid at all?
Re:Sqids – Generate Short Unique IDs from Numbers
by hot_gril on Monday November 27, 2023 @10:12PM
(#38441840)
> Where do you have unique ids that aren’t the primary key?
For things that need public IDs, I always generate and store uuid4s* to avoid leaking database state or anything like that. Even uuid7 leaks creation timestamps. It's cheap and easy to map public IDs to/from PKs at the API boundaries.
* possibly encoded as something nicer like base64 for APIs or URLs
Where do you have unique ids that aren’t the primary key? I would be more interested in a retrospectively unique truncated encoding for extant ulid/uuid; ie given that we’ve passed timestamp foo, we know that (where no external data is merged) we only need a bucketed time granularity of x for the random component of the id to remain unique (for when sortability is no longer needed).
Or just more generally a way to convert a ulid/uuidv7 to a shorter sequence if we are using it for external hash table lookups only and can do without the timestamp component.