Dynamic Queries in Ecto

Enum.reduce can do that quite nicely (you need to aggregate the dynamic not overwrite it on each iteration).