-
Notifications
You must be signed in to change notification settings - Fork 54
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
:stringconfiguration 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.UUIDand handle binary ids as strings. - How do the
:uuidcolumn type and:uuid_typeconfiguration play into this? From my quick testing this type seems to always be handled as strings,:uuid_typeonly 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).