remove binary_id support

This commit is contained in:
Dennis Beatty 2024-07-18 07:24:18 -06:00
parent 6af1efe6d3
commit a71c21e5c3
No known key found for this signature in database
GPG key ID: CF0FEE7E6719D59C
2 changed files with 7 additions and 10 deletions
README.md
lib/type_id

View file

@ -40,11 +40,9 @@ end
### Underlying types
`TypeID`s can be stored as `:string`, `:binary_id`, or `:binary`. `:string` will
store the entire TypeID including the prefix. `:binary` and `:binary_id` store
only the UUID portion and require a `:uuid` or `:binary` column. `:binary_id`
will use UUIDv4 (non K-sortable), whereas `:binary` will use UUIDv7, so
`:binary` is recommended over `:binary_id` for that reason.
`TypeID`s can be stored as either `:string` or `:binary`. `:string` will store
the entire TypeID including the prefix. `:binary` stores only the UUID portion
and requires a `:uuid` or `:binary` column.
#### Default type

View file

@ -48,7 +48,6 @@ if Code.ensure_loaded?(Ecto.ParameterizedType) do
case {tid.prefix, type} do
{^prefix, :string} -> {:ok, TypeID.to_string(tid)}
{^prefix, :binary_id} -> {:ok, TypeID.uuid(tid)}
{^prefix, :binary} -> {:ok, TypeID.uuid_bytes(tid)}
_ -> :error
end
@ -67,12 +66,12 @@ if Code.ensure_loaded?(Ecto.ParameterizedType) do
end
end
def load(<<_::128>> = uuid, _, %{type: type} = params) when type in [:binary_id, :binary] do
def load(<<_::128>> = uuid, _, %{type: :binary} = params) do
prefix = find_prefix(params)
TypeID.from_uuid_bytes(prefix, uuid)
end
def load(<<_::288>> = uuid, _, %{type: type} = params) when type in [:binary_id, :binary] do
def load(<<_::288>> = uuid, _, %{type: :binary} = params) do
prefix = find_prefix(params)
TypeID.from_uuid(prefix, uuid)
rescue
@ -96,8 +95,8 @@ if Code.ensure_loaded?(Ecto.ParameterizedType) do
end
end
unless type in ~w[string binary_id binary]a do
raise ArgumentError, "`type` must be `:string`, `:binary_id`, or `:binary`"
unless type in ~w[string binary]a do
raise ArgumentError, "`type` must be `:string` or `:binary`"
end
if primary_key do