Maps Ecto schema field types to Elixir typespec AST.
Given an Ecto type (e.g. :string, {:array, :integer},
{:assoc, %Ecto.Association.Has{...}}), this module produces the
corresponding quoted Elixir type for use in @type definitions.
Summary
Functions
Converts an Ecto field type into a quoted Elixir typespec.
Functions
Converts an Ecto field type into a quoted Elixir typespec.
Recognised options
:type- When present, returned as-is (user-supplied type override).:enum_values- List of atoms forEcto.Enumfields; produces a union type (e.g.:active | :inactive).
All other keys in opts are ignored by this function but may be
passed through for convenience.
Type Mapping
| Ecto type | Elixir typespec |
|---|---|
:string | String.t() |
:integer | integer() |
:float | float() |
:boolean | boolean() |
:binary | binary() |
:bitstring | bitstring() |
:decimal | Decimal.t() |
:id | integer() |
:binary_id | Ecto.UUID.t() |
:map | map() |
:array | list() |
:date | Date.t() |
:time / :time_usec | Time.t() |
:naive_datetime / :naive_datetime_usec | NaiveDateTime.t() |
:utc_datetime / :utc_datetime_usec | DateTime.t() |
:duration | Duration.t() |
{:map, inner} | %{term() => inner_type} |
{:array, inner} | list(inner_type) |
belongs_to | Ecto.Schema.belongs_to(Schema.t()) |
has_one | Ecto.Schema.has_one(Schema.t()) |
has_many | Ecto.Schema.has_many(Schema.t()) |
many_to_many | Ecto.Schema.many_to_many(Schema.t()) |
embeds_one | Schema.t() |
embeds_many | list(Schema.t()) |
Ecto.Enum | union of atom values or atom() |
| Other module | Module.t() |
Returns
A quoted expression representing the Elixir typespec.
Raises ArgumentError for unsupported types.