Skip to content

[Uid] Add some ulid helpers to manipulate the binary field saved in db #42966

@maidmaid

Description

@maidmaid

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 :


/app # bin/console ulid:inspect 01FF2QE789KQSBK3HWT65S9H7S
 ---------------------- -------------------------------------- 
  Label                  Value                                 
 ---------------------- -------------------------------------- 
  toBase32 (canonical)   01FF2QE789KQSBK3HWT65S9H7S            
...
  toHex                  0x017BC5771D099DF2B98E3CD18B94C4F9  

Thus, the hex representation can be used directly in a SQL request to filter a specific ulid :

SELECT * FROM my_table WHERE id=0x017BC5771D099DF2B98E3CD18B94C4F9

A second idea is to bring some SQL routimes to manipulate ulid directly in SQL as you can see in this gist.

SELECT * FROM my_table WHERE id=ULID_DECODE('01FF2QE789KQSBK3HWT65S9H7S')

It could be a Doctrine migration that the developer is free to use in his app.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions