UUID.Ecto.Type behaviour (UUID v1.6.0) View Source

Ecto UUID type.

Link to this section Summary

Functions

Used to create a normal Ecto.Type.

Casts to UUID.

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Converts a string representing a UUID into a binary.

Callback implementation for Ecto.ParameterizedType.embed_as/2.

Converts a binary UUID into a string.

Callbacks

Generates a UUID in the binary format.

Generates a UUID.

Link to this section Types

Specs

params() :: {uuid_type(), uuid_type_args()}

Specs

uuid_type() :: :uuid1 | :uuid3 | :uuid4 | :uuid5 | :uuid6

Specs

uuid_type_args() :: [term()]

Link to this section Functions

Link to this macro

__using__(opts)

View Source (macro)

Used to create a normal Ecto.Type.

Defining a UUID Ecto type

defmodule Foo.Types.UUID6 do
  use UUID.Ecto.Type,
    type: :uuid6,
    node_type: :random_bytes
end

Using

defmodule Foo.Bar do
  use Ecto.Schema

  alias Foo.Types.UUID6

  @primary_key {:id, UUID6, autogenerate: true}

  schema "foo" do
    field :bar_id, UUID6
  end
end

Specs

cast(UUID.t(), params()) :: {:ok, UUID.str()} | :error

Casts to UUID.

Specs

cast!(UUID.t(), params()) :: UUID.str()

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Link to this function

dump(value, dumper, params)

View Source

Specs

dump(UUID.str(), function(), params()) :: {:ok, UUID.raw()} | :error

Converts a string representing a UUID into a binary.

Callback implementation for Ecto.ParameterizedType.embed_as/2.

Link to this function

load(value, loader, params)

View Source

Specs

load(UUID.raw(), function(), params()) :: {:ok, UUID.str()} | :error

Converts a binary UUID into a string.

Link to this section Callbacks

Specs

bingenerate() :: UUID.raw()

Generates a UUID in the binary format.

Specs

generate(UUID.type()) :: UUID.t()

Generates a UUID.