-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Uid] Add some ulid helpers to manipulate the binary field saved in db #42966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Idea 1 sounds reasonable. About idea 2: I don't think we want to maintain stored procedures for various database engines. 🤔 |
I might be wrong but isn't the RFC 4122 representation the same as hexadecimal representation of your UUID? |
RFC 4122 representation is like |
I'm telling this because after trying a few things, I realized that RFC 4122 seems equal to the hex representation but with additional dashes. I tested with the ULID you gave, $ php bin/console ulid:inspect 01FF2QE789KQSBK3HWT65S9H7S
---------------------- --------------------------------------
Label Value
---------------------- --------------------------------------
toBase32 (canonical) 01FF2QE789KQSBK3HWT65S9H7S
toBase58 1BdEv7iG455d3N8R8cVcGx
toRfc4122 017bc577-1d09-9df2-b98e-3cd18b94c4f9
toHex 0x017bc5771d099df2b98e3cd18b94c4f9
---------------------- --------------------------------------
Time 2021-09-08 12:52:02.953 UTC
---------------------- -------------------------------------- If this is correct, I'm not sure of the additional value of adding the hex representation? |
I believe that inspect should return uid in all awailable formats which includes binary formated as hex. |
Thank you for this suggestion. |
Could I get a reply or should I close this? |
I think this is a useful feature, don't close this. |
…urimasniekis) This PR was merged into the 6.2 branch. Discussion ---------- [Uid] Added toHexString method to AbstractUid class | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Fix | #42966 | License | MIT Added a small method to Uid component `AbstractUid` class called `toHex` which would output binary value of identifier as prefixed hex string for e.g. `0x0000000`. This is really useful when using with Doctrine for Id generation as the storage of Uid is a binary format in the database, and in most cases, it is usually used with hex format to query it. This PR is from #45939 as I needed to change the source branch to 6.1 Commits ------- dad28d6 Added toHexString method to AbstractUid class
Description
As ulid is saved as a binary field in the db and represented as base32 in the application side, it's hard and unconvenient to manipulate them. It would be interesting to improve the DX.
Example
1st idea :
bin/console inspect:ulid
could show an hexadecimal representation of the ulid :Thus, the hex representation can be used directly in a SQL request to filter a specific ulid :
A second idea is to bring some SQL routimes to manipulate ulid directly in SQL as you can see in this gist.
It could be a Doctrine migration that the developer is free to use in his app.
The text was updated successfully, but these errors were encountered: