Drops.Relation.Schema.Field (drops_relation v0.1.0)
View SourceRepresents a field in a database table/schema.
This struct stores comprehensive information about a database field including its name, type information, and source mapping.
Examples
# Simple field
%Drops.Relation.Schema.Field{
name: :email,
type: :string
}
Summary
Functions
Merges two Field structs, with the right field taking precedence.
Creates a new Field struct.
Types
@type meta() :: %{ optional(:type) => term(), optional(:adapter) => atom(), optional(:source) => atom(), optional(:nullable) => boolean() | nil, optional(:default) => term() | nil, optional(:check_constraints) => [String.t()] | nil, optional(:primary_key) => boolean() | nil, optional(:foreign_key) => boolean() | nil, optional(:association) => boolean() | nil }
Functions
Merges two Field structs, with the right field taking precedence.
This function is useful for combining inferred fields with custom fields, where custom fields should override inferred properties while preserving metadata from both sources.
Parameters
left
- The base field (typically inferred)right
- The field to merge (typically custom, takes precedence)
Examples
iex> inferred = Drops.Relation.Schema.Field.new(:email, :string, :string, :email, %{nullable: true})
iex> custom = Drops.Relation.Schema.Field.new(:email, :string, {:parameterized, {Ecto.Enum, %{values: [:active, :inactive]}}}, :email)
iex> merged = Drops.Relation.Schema.Field.merge(inferred, custom)
iex> merged.type
{:parameterized, {Ecto.Enum, %{values: [:active, :inactive]}}}
iex> merged.meta.nullable
true
Creates a new Field struct.
Parameters
name
- The field name as an atomtype
- The normalized type (e.g., :string, :integer)type
- The original Ecto typesource
- The source column name in the databasemeta
- Optional metadata map with nullable, default, check_constraints
Examples
iex> Drops.Relation.Schema.Field.new(:email, :string, :string, :email)
%Drops.Relation.Schema.Field{
name: :email,
type: :string,
type: :string,
source: :email,
meta: %{}
}
iex> meta = %{nullable: false, default: "active"}
iex> Drops.Relation.Schema.Field.new(:status, :string, :string, :status, meta)
%Drops.Relation.Schema.Field{
name: :status,
type: :string,
type: :string,
source: :status,
meta: %{nullable: false, default: "active"}
}