Hey guys, so I’m in need of help understanding how can I use Enum.map
in my query. I’m doing some DB querying and pagination and all works fine, but I’ll need to do more clear data representation and I have a JSONB field in my DB which I need to break down.
My goal is to do something like this
def google_news_query(google_news_scope) do
from n in google_news_scope,
select: %{
news: Enum.map(n.news, fn n -> %{
relevance_score: n.relevance_score
}
end
)}
end
But I guess I can’t because of
(Ecto.Query.CompileError) Enum.map(n.news, fn n -> %{relevance_score: n.relevance_score} end) is not a valid query expression. If you want to invoke Enum.map/2 in a query, make sure that the module Enum is required and that map/2 is a macro
Is this achievable? How can I create a macro that can help me do additional Enum over the queried data?