What is the meaning of '=>' ? Repo.all()

Hi guys, I hope that all are good, now, Im trying to make a query into a function but when I sent the query for repo.all, this is the answer is ‘=>’ that the repo give me. does anyone know about it ? :thinking:

defp historia_clinica_medico(paciente)do

IO.inspect(Repo.all(from h in Sim.HistorialHistoriaClinica, where: h.paciente_id == ^paciente
                                                                 and not is_nil(h.historiaclinicamedico_id), select: h.historiaclinicamedico_id))

end

thank you for all advices as much as code or my poor English language

There really isn’t enough information to give an answer. For example:

iex(1)> alias MusicDB.Track
MusicDB.Track
iex(2)> import Ecto.Query
Ecto.Query
iex(3)> album_id = 5
5
iex(4)> IO.inspect(Repo.all(from t in Track, where: t.album_id == ^album_id and not is_nil(t.id), select: t.id))

20:04:17.914 [debug] QUERY OK source="tracks" db=2.0ms
SELECT t0."id" FROM "tracks" AS t0 WHERE ((t0."album_id" = $1) AND NOT (t0."id" IS NULL)) [5]
[33, 32, 31, 30]
[33, 32, 31, 30]
iex(5)>

=> typically appears in the representation of Elixir maps where the keys aren’t atoms.

iex(5)> IO.inspect(Map.new([{"a",1},{"b",2}]))
%{"a" => 1, "b" => 2}
%{"a" => 1, "b" => 2}
iex(6)> 

1 Like

Peerreynders may you check the controller ?
https://gist.github.com/juanldslv/e03a05244f6dc1a2c86869331f844ff8

This looks suspiciously like iex displaying a list of integers as charlists. Can you try the following in iex?

result = Repo.all(from h in Sim.HistorialHistoriaClinica, where: h.paciente_id == ^paciente
        and not is_nil(h.historiaclinicamedico_id), select: h.historiaclinicamedico_id)

inspect result, char_lists: :as_lists

i result

Does the result make more sense to you? If yes, you can find more information about it in the charlists section of the guide, and this issue has helpful information also.

4 Likes

In particular:

iex(1)> list_of_ids = [61, 62]
'=>'
iex(2)> IO.inspect(list_of_ids)
'=>'
'=>'
iex(3)> IO.inspect(list_of_ids, [charlists: :as_lists]) 
[61, 62]
'=>'
iex(4)> to_string(list_of_ids)
"=>"
iex(5)>

i.e. the query returned a list of two historiaclinicamedico_id values, 61 and 62 respectively.

2 Likes

Thank you @david_ex, that works like a charm… best regards :robot: :+1:

Thank you @peerreynders , that works like a charm… best regards :robot: :+1: