PhoenixMicro.Schema.Field (PhoenixMicro v1.0.0)

Copy Markdown View Source

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: false

Supported types

TypeElixir check
:stringis_binary/1
:integeris_integer/1
:floatis_float/1 or integer
:booleanis_boolean/1
:mapis_map/1
:listis_list/1
:atomis_atom/1 or binary
:anyalways 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

field_type()

@type field_type() ::
  :string | :integer | :float | :boolean | :map | :list | :atom | :any

t()

@type t() :: %PhoenixMicro.Schema.Field{
  default: term(),
  description: String.t() | nil,
  name: atom(),
  required: boolean(),
  type: field_type()
}

Functions

new(name, type, opts \\ [])

@spec new(atom(), field_type(), keyword()) :: t()

Builds a Field struct from the DSL arguments.

valid_type?(v, atom)

@spec valid_type?(term(), field_type()) :: boolean()

Returns true if the value matches the given type.

validate_value(field, value)

@spec validate_value(t(), term()) :: :ok | {:error, String.t()}

Validates a single value against this field's type. Returns :ok or {:error, message}.