Ecto.DataType
Ecto.DataType protocol
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登录查看完整内容