Search code examples
hashhashids

HashIds - To Store Hash in DB or Not To


I am trying to figure out the best practices with using Hashids and if I should be storing my hash ids in a column in my db or should I be using it as demonstrated within the documentation. i.e. Encoding the Id in one area, decoding it in another.

With my current setup, I have been encoding all of my primary key id's and decoding them when the values are publicly accessible, which is the intended purpose of the module, but I'm worried that the hashes that were uniquely generated for my id's will change at some point in the future, which could cause issues like link share-ability for my application.

Based on this scenario, should I really be storing the generated hash into a column in my db and query that?


Solution

  • Regarding whether you should store the Id or not in the database is really up for you to decide. I would say there is no need to do that.

    Whether the hashes will change in the future or not really depends on you updating the package or not, from the page;

    Since produced ids might differ after updates, be sure to include exact version of Hashids, so you don't unknowingly change your existing ids.

    Don't know which version you are using but I'm the author of the .NET version and I've been trying to follow Semantic Versioning meaning with bug fixes I increase patch, added features (non breaking) increases minor. Would there be a change in how the hashes are generated I would increase major.