After import Ecto.Query, we can write and run query to collect data from database
alias Mandeeoo.Repo
alias Mandeeoo.Type
query = from t in Types,
join: b in Blog, on b.type_id == t.id
select: t.name
Repo.all(query)
However, we don't need to define the whole query at once. We can write it in small steps.
alias Mandeeoo.Repo
alias Mandeeoo.Type
query = Type
query = from t in Query, join: b in Blog, on b.type_id == t.id
query = from t in Query, select: t.name
Repo.all(query)
We can write the query in small steps. This strategy works because Ecto defines something called the Queryable protocol.
import Ecto.Query
, we can write and run query to collect data from databaseWe can write the query in small steps. This strategy works because Ecto defines something called the Queryable protocol.
Queryable Protocol: Converts a data structure into an Ecto.Query.