Return Ecto query tuple as json in Phoenix

I’m having some issues with my Json API and Ecto. I’m getting a bunch of data from the database with the following code:

    query = from message in "messages",
      where: ^id ==,
      select: {message.message,,}
    messages = Repo.all(query)

I then pass these messages into a view function and run through it with the following code:

  def render("chat.json", %{messages: messages}) do
    Enum.each(messages, fn message ->
      render(ChatView, "message.json", message: message)

In the message.json function I’m trying to print out the three selected fields, which as faar as I understand are in a query:

  def render("message.json", %{message: message}) do
      message: elem(message, 0),
      id: elem(message, 1),
      room: elem(message, 2)

If I print out the message in the render function, it prints out the corrent content. But the code above simple returns “ok” without any other content or errors.
What am I doing wrong?

Enum.each/2 returns :ok and discards the return value of the function passed to it docs. You likely want here.

I think render_many works here, Please do check