Establishing an API
Let’s learn how to perform some operations on our responses in our SQL database.
Let’s move on to the main API at mastery_persistence.ex
. For this project, our API exists to save and fetch items from an SQL database. For the most part, our API will consist of Ecto
queries that collect and aggregate responses in various ways.
Saving and querying our responses
It’s time to open up /mastery_persistence/lib/mastery_persistence.ex
to save and query our responses:
Press + to interact
defmodule MasteryPersistence doimport Ecto.Query, only: [from: 2]alias MasteryPersistence.{Response, Repo}end
We import Ecto.Query
and alias our Repo
and Response
modules because this file will exist to provide a SQL-focused API to access Mastery responses.
Inserting changes
Now, we can ...