The Repo Module
Learn about the Repo module.
We'll cover the following
The heart of Ecto
Now that we’ve got a handle on what a repository is, let’s look at how it’s implemented in Ecto. The Repo
module is the heart of Ecto, and just about everything we do will touch Repo
somehow. The Repo
module is also quite powerful. We can perform all of the classic CRUD operations (create, read, update, and delete) using just the Repo
module. The other modules in Ecto make these operations easier, but there’s a lot we can do with Repo
.
Repo’s functionality
Given its relationship to the repository pattern, Repo
contains many functions, such as get
, insert
, update
, delete
, and the like. We never call these functions directly. Instead, we create our own Repo
module that lives in the application’s codebase, then integrate Ecto.Repo's
functions with Elixir’s use
macro. In our sample project lib/music_db/repo.ex
, we’ll see the following.
Get hands-on with 1400+ tech skills courses.