We can use select_merge ro build a long query bit by bit in which multiple selects are used.
This is my code:
query = from p in Model, select: %{}
query = if k == "$avg" do
from p in query, select_merge: %{avg: avg(p.id)}
else
query
end
query = if k == "$count" do
from p in query, select_merge: %{count: count(p.pass)}
else
query
end
On console after inspecting query I got these results:
#Ecto.Query<from m Model, select: %{avg: avg(m.id)}>
#Ecto.Query<from m in Model, select: %{count: count(m.pass)}>
And final query is:
#Ecto.Query<from m in Model, select: %{}>
In the final query the select is empty. It suppose to have contain both the above queries inside of it.
Any help will be much appreciated
Thanks