I have made a complicated SQL. so that I use raw query.
I've already referred https://stackguides.com/questions/36042888/raw-sql-with-ecto
But I still stacked.
query = "select item_id, sum(unit) amount from sales where item_id = ? "
result = Ecto.Adapters.SQL.query(Repo, query, [item_id])
However I have no idea how to retrieve DB values like Ecto results in general. I hope I get values like Map with key & value whatever.
The result is blow.
%Mariaex.Result{columns: ["item_id", "amount"], connection_id: nil, last_insert_id: nil, num_rows: 1, rows: [[42, #Decimal<4>]]}, :get, [])
Should I retrieve by myself or there are general and smart way? Hopefully, the last result is output for Phoenix templates html.
I'm trying to change result value to Map like this.
item_result =
{:ok, result} ->
rows = result.get(:rows)
columns = result.get(:columns)
Enum.zip(columns, rows)
But it is hard for elixir novice.