This talk is about big ideas around Ecto structure and how  to use it.

Ecto follows the Repository Pattern ( for data access, it is a centralized class connected to a database, the rest of the operations are sent to the repository. There is different way to update a value with Ecto, by using Changeset for example. Every time you see the word "Repo", the code is talking to the database.

Ecto is Explicit. The schema definition is pretty easy to use, we need to use Ecto.Schema ( module, define a schema with schema ( and define different fields in the specific schema.

Ecto supports notion of association and how to define relation between table. A schema can be connected to another schema by using belongs_to function ( In the other schema, we can now define the other part of the association with has_many ( or has_one ( functions.

Associations should me loaded to see the data associated with the schema. Ecto doesn't support Lazy Loading, you need to define exactly what data you need to load with Repo.preload/2 function (

Ecto manipulated operations and SQL queries/requests as data-structure. We have 3 ways of using these data-structure: with Query module (, an integrated version of SQL in Elixir, these queries are composable and reusable.

Changeset ( module and data-structure defines how to filter , validate the data and capture errors. To create a Changeset, we need to cast the structure and pipe it in different Changeset function present in the module. Validation is part of the changeset and not of the schema, because validation can change during the evolution of your application. Multiple changesets can me set at the same time.

Multi module ( can manage multiple operations at the same time, as transaction. If something fail during a multiple operation, we go back in the last state without pushing data in the database. Nothing happened if we don't call Repo.transaction function ( Multi can run arbitrary piece rof code, like sending an email when we insert something in the database. Data-structure can be composed and reuse somewhere else in the code.

If you don't need schema, it is not mandatory to use it, queries can be written only with Query module ( Schema can be bended, it is possible to add virtual field by using virtual option, it permit to define, for example, two type of data, string, and integer, to be stored in the same place. This feature is used directly with changeset.

Embedded schema ( can be used to define "virtual" schema, and add more flexibility to some data which can fit perfectly in the database.

A good thing about Ecto is you can pick what you need and drop the rest. Use only what it is useful for you.