Description
When I tried using binary_id
primary keys for my tables, I was surprised to see IDs in elixir's binary format rather than strings. After some research, I found the (undocumented) :binary_id_type
option.
The option supports either :string
(default) or :binary
as values. I was surprised to find in the loader for binary_id
that the :binary
(rather than :string
) type uses Ecto.UUID
(and consequently handles IDs as strings). The actual SQLite column types do seem to match the configuration more intuitively: :binary
-> UUID
column with BLOB
affinity, :string
-> TEXT_UUID
column with TEXT
affinity.
My resulting questions are:
- Why does this parameter exist? Does the raw binary save space in the database?
- Shouldn't the
:string
configuration be the one to useEcto.UUID
(and therefore handles IDs as plain strings). That would be much more intuitive to me. - Whatever the answer to question 2 is, should the default behavior be to handle UUID columns as plain strings? This would be more in line with the ecto_sql's builtin sql adapters, which all make use of
Ecto.UUID
and handle binary ids as strings. - How do the
:uuid
column type and:uuid_type
configuration play into this? From my quick testing this type seems to always be handled as strings,:uuid_type
only affecting the type of the column in SQLite itself.
When I get some clarification on this I'd be more than happy to contribute the necessary documentation (and code if applicable).