Elixir Postgrex using uuid

2572 views elixir
-4

i am using Postgrex library for my database, and i have the following problem: One of my column in the database is from type uuid, i am using the UUID module in elixir but whenever i am trying to persist something on the databse i get the following error: Postgrex expected a binary of 16 bytes, got "3c5fda26-ea3b-4c77-8f19-06e106a61eda", i have tried to store it as plain string but it was not possible as you can see, how should i convert the uuid before persisting it to the database?

answered question

1 Answer

13

UUID is a string, but not a "human readable string". What you see as 3c5fda26-ea3b-4c77-8f19-06e106a61eda is not UUID, it is only one of the possible human readable representations. What you need is to pass direct, internal, UUID representation which in fact is binary of 16 bytes. To parse string form it hexadecimal representation to binary representation you can use Ecto.UUID.dump/1.

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories