3 ms·
I’m currently prototyping a little database+api+cli todo app and I want identifiers that can be abbreviated in the same way as partial git commit hashes can be
by vbsteven 5y ago
I’m currently prototyping a little database+api+cli todo app and I want identifiers that can be abbreviated in the same way as partial git commit hashes can be used on the command line. What should I use?
I was thinking of generating random character strings and simply retry when the db throws duplicate key error on insert. No sharding is necessary and I’d like to have efficient foreign keys. Any thoughts?
- mutatio 5y agoYou could use a serial int and just hex-encode when interacting with the CLI? You could then use range queries to match short hashes by zeroing out the remaining bytes and using >=
- alexis2b 5y agoYou could try NanoID[0]? Seems available in many languages. [0] https://blog.bibekkakati.me/nanoid-alternative-to-uuid https://blog.bibekkakati.me/nanoid-alternative-to-uuid
- adav 5y agoCheck out linear congruential generators or other pseudorandom number generators. Then map the resulting number to letters.