Skip to content

MySQL UUIDs stored as CHAR(36) #4997

Closed
Closed

Description

@nimish

UUIDs are 128 bit integers, which means they should fit into BINARY(16), but sequelize generates CHAR(36) strings instead-- a rather huge increase in size.

Is there a way to get binary(16) support in?

Activity

  1. mickhansen commented on Dec 16, 2015

    @mickhansen
    Contributor
  2. added
    dialect: mysql
    good first issue
    on Jan 18, 2016
  3. stale commented on Jun 29, 2017

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

  4. rafaelalmeidatk commented on Mar 20, 2018

    @rafaelalmeidatk

    I began working on this issue and the database is already using the BINARY(16) format, but it shows the binary format to the user. How can I apply a function to the field before returning it?

  5. omidkrad commented on Apr 5, 2018

    @omidkrad

    Maybe Sequelize should support UUID.BINARY data type.
    See related issue: #9271

  6. bradennapier commented on Dec 11, 2018

    @bradennapier

    Note that in #9271 I posted my working solution to accomplish this.

  7. Rudedog9d commented on Jan 15, 2019

    @Rudedog9d

    @rafaelalmeidatk Could you leverage BIN_TO_UUID to convert the bytes to UUID?

    Check out this article for more: https://mysqlserverteam.com/mysql-8-0-uuid-support/

  8. bradennapier commented on Jan 15, 2019

    @bradennapier

    @Rudedog9d see that #10290 already implements that natively without the need. In addition you can utilize it without the need for MySQL / MySQL 8 by utilizing the libraries i built for them:

    https://github.com/odo-network/sequelize-binary-uuid

    https://github.com/odo-network/binary-uuid

    which implement an identical effect.

    I originally used the BIN_TO_UUID function as mentioned but it would have a strong dependency on instance type/version and it required multiple round-trips since it required calling the fn to get a uuid then creating the row after. Since async wasn't possible in getters it required the use of hooks instead which was a problem.

    The package sequelize-binary-uuid provides the optimum and easiest solution. I didn't pursue the PR further because it seemed it made most sense this way. It also has the benefit of building a virtual key for you which makes it much easier to work with the binary uuid itself since you always can reference the string representation.

  9. omidkrad commented on Jan 18, 2019

    @omidkrad

    @bradennapier thanks, this is great. I wished I could use sequelize-binary-uuid with sequelize-typescript. If this gets added to sequelize, there's a good chance that they also add it to sequelize-typescript.

  10. bradennapier commented on Jan 18, 2019

    @bradennapier

    @omidkrad well the good news is my company is switching to 100% typescript so... I’d imagine it will be supported soon :)

    They just decided to wait to see if there’s enough demand for binary uuid in this way so make sure you indicate your support for it officially as well :)

  11. spencerwasden commented on Nov 29, 2020

    @spencerwasden

    @bradennapier

    @omidkrad well the good news is my company is switching to 100% typescript so... I’d imagine it will be supported soon :)

    They just decided to wait to see if there’s enough demand for binary uuid in this way so make sure you indicate your support for it officially as well :)

    Any developments on using this with sequelize-typescript?

  12. bradennapier commented on Dec 2, 2020

    @bradennapier

    @spencerwasden
    Any developments on using this with sequelize-typescript?

    It shouldn't be difficult to use the package with sequelize-typescript - you'd need to make the typings for now but it would be relatively straight forward/simple.

    Actually it couldn't have been 100% typed until the recent 4.1 launch which would allow adding custom-named keys to the types but I am not sure my bandwidth would have me updating that any time soon...

    Ideally sequelize would add this for official support :-P

  13. github-actions commented on Nov 16, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mysqlgood first issuestale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions