Represents a single field definition in a PhoenixMicro.Schema.
Fields are defined via the field/2 and field/3 macros:
field :payment_id, :string, required: true
field :amount_cents, :integer, required: true
field :currency, :string, required: true, default: "USD"
field :metadata, :map, required: falseSupported types
| Type | Elixir check |
|---|---|
:string | is_binary/1 |
:integer | is_integer/1 |
:float | is_float/1 or integer |
:boolean | is_boolean/1 |
:map | is_map/1 |
:list | is_list/1 |
:atom | is_atom/1 or binary |
:any | always passes |
Summary
Functions
Builds a Field struct from the DSL arguments.
Returns true if the value matches the given type.
Validates a single value against this field's type.
Returns :ok or {:error, message}.
Types
@type field_type() ::
:string | :integer | :float | :boolean | :map | :list | :atom | :any
@type t() :: %PhoenixMicro.Schema.Field{ default: term(), description: String.t() | nil, name: atom(), required: boolean(), type: field_type() }
Functions
@spec new(atom(), field_type(), keyword()) :: t()
Builds a Field struct from the DSL arguments.
@spec valid_type?(term(), field_type()) :: boolean()
Returns true if the value matches the given type.
Validates a single value against this field's type.
Returns :ok or {:error, message}.