Giter Club home page Giter Club logo

Comments (12)

vinkla avatar vinkla commented on July 17, 2024 3

We don't recommend to store the hashids in the database. Instead encode/decode them on the fly.

Use it when you don't want to expose your database numeric ids to users.

from hashids.

peterchaula avatar peterchaula commented on July 17, 2024 1

So the hashes are unique, and the behaviour is correct, the only issue is with your database being case insensitive.

from hashids.

eugene-borovov avatar eugene-borovov commented on July 17, 2024 1

Setting up a collation in the database may help you.
https://dev.mysql.com/doc/refman/8.0/en/case-sensitivity.html
https://stackoverflow.com/a/6448861

from hashids.

vinkla avatar vinkla commented on July 17, 2024

If you think you've found a bug. Please provide a failing test case in the HashidsTest test class in a pull request.

from hashids.

j8n avatar j8n commented on July 17, 2024

Something similar happened to me!

Error reproduction
$hash = (new Hashids\Hashids('App\Models\Model'.'_string', 16))->encode(545) --> "KQAd7lo8XLogXG69"
$hash = (new Hashids\Hashids('App\Models\Model'.'_string', 16))->encode(501) --> "KQAd7lo8JLWgXG69"

from hashids.

vinkla avatar vinkla commented on July 17, 2024

@j8n as you can see, these are not the same hashes:

KQAd7lo8XLogXG69
KQAd7lo8JLWgXG69

from hashids.

j8n avatar j8n commented on July 17, 2024

Yes ok, I cannot reproduce the error again (with test data). I had a "Integrity constraint violation: 1062 Duplicate entry" for a hash id in a record

from hashids.

j8n avatar j8n commented on July 17, 2024

Ok, just to share the original as in my production env:

$hash = (new Hashids\Hashids('App\Models\Subscription'.'_OUTGO', 16))->encode(501); --> "P17zevgVkZExk80a"
$hash = (new Hashids\Hashids('App\Models\Subscription'.'_OUTGO', 16))->encode(545); --> "P17zevgVKZExk80a"
The only change is the case of the "K"

That's how I got the error above

from hashids.

vinkla avatar vinkla commented on July 17, 2024

The only change is the case of the "K"

This is the expected behaviour.

from hashids.

j8n avatar j8n commented on July 17, 2024

What's the use of Hashids lib, if we get a "Integrity constraint violation" error in the database? The database seems to understand the case incorrectly.
What do I have to do?

from hashids.

j8n avatar j8n commented on July 17, 2024

ok thanks

from hashids.

hazem-taha avatar hazem-taha commented on July 17, 2024

I'm saving the hashids to the DB and it is not possible to refactor the system, is there a way to make the DB queries in laravel to be case sensitive ?

from hashids.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.