Home

ecto

Ecto is a domain-specific language and toolkit for data mapping and persistence in Elixir applications. It provides a consistent way to define how data is structured, loaded from and stored to a database, and how changes are validated and applied. Ecto focuses on a repository pattern and a composable query DSL, enabling developers to write database operations that are explicit, testable, and free from ad-hoc SQL.

Key components include the Ecto.Repo, which acts as a database wrapper; Ecto.Schema for mapping Elixir structs

Ecto supports associations (has_many, belongs_to), embeds for nested data, and preloading of associations to avoid N+1

Applications typically define schemas, write changesets, and interact with the database via Repo functions (insert, update,

to
database
tables;
Ecto.Changeset
for
validation,
casting,
and
constraints;
and
Ecto.Query
for
building
queries.
Migrations
are
supported
through
Ecto.Migration
to
evolve
database
schemas
over
time.
queries.
Changesets
enable
data
cleansing
and
constraint
enforcement,
with
features
such
as
optimistic
locking.
The
system
is
database-agnostic
through
adapters,
with
PostgreSQL
being
the
most
common
backend,
but
other
databases
are
supported
through
adapters.
delete,
get)
and
queries
constructed
with
Ecto.Query.
Ecto
is
commonly
used
with
the
Phoenix
web
framework
as
the
primary
persistence
layer.