Hi, I’m new to Elixir and Phoenix.
I’m doing some experiments with Ecto.Adapters.SQL.query and now I would like to render a query result into an HTML table.
So far I did this:
page_controller.ex:
def hello(conn, _params) do
{:ok, result} = Ecto.Adapters.SQL.query(:"Elixir.Hello.repo", "select idstudy, modality from study order by idstudy", [])
render(conn, "hello.html", studies: result)
end
hello.html.heex
<section class="phx-hero">
<h1>Hello!</h1>
<table>
<%= for study <- @studies do %>
<tr>
<td><%= study.idstudy %></td>
<td><%= study.modality %></td>
</tr>
<% end %>
</table>
</section>
When I run that code I get this:
##### Protocol.UndefinedError <small>at GET</small> <small>/hello</small>
# protocol Enumerable not implemented for %Postgrex.Result{columns: ["idstudy", "modality"], command: :select, connection_id: 4334, messages: [], num_rows: 8, rows: [[12070, "CR"], [12071, "MR"], [12072, "CR"], [12073, "MR"], [12074, "CR"], [12075, "CR"], [12076, "CR"], [12077, "MR"]]} of type Postgrex.Result (a struct)