Ecto v2.2.7 Ecto.DataType protocol View Source

Casts and dumps a given struct into an Ecto type.

While Ecto.Type allows developers to cast/load/dump any value from the storage into the struct based on the schema, Ecto.DataType allows developers to convert existing data types into primitive Ecto types without the schema information.

For example, Elixir’s native Date struct implements the Ecto.DataType protocol so it is properly converted to a tuple when directly passed to adapters:

defimpl Ecto.DataType, for: Date do
  def dump(%Date{day: day, month: month, year: year}) do
    {:ok, {year, month, day}}
  end
end

Link to this section Summary

Functions

Invoked when the data structure has not been dumped along the way and must fallback to its database representation

Link to this section Types

Link to this section Functions

Link to this function dump(value) View Source
dump(term()) :: {:ok, term()} | :error

Invoked when the data structure has not been dumped along the way and must fallback to its database representation.