Query Data with Ecto.Query

Ecto provides robust query functions—you can write most queries without writing SQL by hand. And if you run into a query that can’t be written with the Ecto query language, you can safely use handwritten SQL.

We’re going to build our data layer—everything needed to query and persist data in our application. The functions and patterns we use will be explained along the way. But first, we need to go over a module that we’re going to use many times in this section.

The Repo Module

The generator that we used to create our application included an important (and simple) module. The PhoneApp.Repo module is how we’ll handle all interactions with the database. The module is only one line of code:

Get From Ruby to Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.