Skip to content

Questions regarding binary_id columns and the binary_id_type configuration #70

Closed
@Blond11516

Description

@Blond11516

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:

  1. Why does this parameter exist? Does the raw binary save space in the database?
  2. Shouldn't the :stringconfiguration be the one to use Ecto.UUID (and therefore handles IDs as plain strings). That would be much more intuitive to me.
  3. 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.
  4. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions