Lessons: Ecto

Interacting with data is a part of most applications. These lessons explore the Ecto library and how to leverage it for our database interactions.

Basics

Ecto is an official Elixir project providing a database wrapper and integrated query language. With Ecto we’re able to create migrations, define schemas, insert and update records, and query them.

Changesets

In order to insert, update or delete data from the database, Ecto.Repo.insert/2, update/2 and delete/2 require a changeset as their first parameter. But what are changesets?

A familiar task for almost every developer is checking input data for potential errors — we want to make sure that data is in the right state, before we attempt to use it for our purposes.

Ecto provides a complete solution for working with data changes in the form of the Changeset module and data structure. In this lesson we’re going to explore this functionality and learn how to verify data’s integrity, before we persist it to the database.

Associations

In this section we’ll learn how to use Ecto to define and work with associations between our schemas.