Enumex.Static.Components.EctoType (Enumex v1.0.0)
View SourceA component that generates an ecto parameterized type for enum values.
Dependencies
Requires Ecto.Type module from :ecto dependency.
Field options
:enum_name(required) - an atom representing the name of the enumfield :status, MyApp.Enums, enum_name: :my_enum:ecto_type- The underlying ecto type to use for storage. Supported values::binary,:binary_idand:stringfor string-based database fields:idand:integer- for integer-based database field
Defaults to
:string.field :status, MyApp.Enums, enum_name: :my_enum, ecto_type: :binary
Example
defmodule MyApp.Enums do
use Enumex.Static, components: [Enumex.Static.Components.EctoType]
# enum definitions go here
end
defmodule MyApp.Schema do
use Ecto.Schema
schema "my_table" do
field :status, MyApp.Enums.Status, enum_name: :my_enum, ecto_type: :binary
end
end