Putting Our Repo to Work

As we saw earlier, Repo is the gateway to our database, and most of the functions in Repo map directly to standard CRUD operations. This makes Repo fairly small compared to some other Ecto modules: its one job is sending payloads back and forth to the database. But we can use this small handful of functions to create, read, update, and delete records. Let’s try it.

Repo exposes a number of functions that allow us to interact with our database at a low level, even before we start setting up schemas. These functions are easy to spot because they end with “all”: insert_all, update_all, delete_all, and just plain all for queries.

For example, our music app includes an artists table. Here’s how we can insert a new record ...

Get Programming Ecto 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.