parikshit
How to get access values from boltsips response data in .eex file
Want to access name and email filed in .eex file
How to iterate thorough Bolt.Sips.Response → results → properties → email,name
%Bolt.Sips.Response{ bookmark: "", fields: ["n"], notifications: [], plan: nil, profile: nil, records: [ [ %Bolt.Sips.Types.Node{ id: 0, labels: ["E"], properties: %{ "email" => "abc@email.com", "name" => "Abc Xyz", } } ] ], results: [ %{ "n" => %Bolt.Sips.Types.Node{ id: 0, labels: ["E"], properties: %{ "email" => "abc@email.com", "name" => "Abc Xyz", } } } ], stats: [], type: "r" }
Marked As Solved
kokolegorille
I didn’t get the structure right. it should be…
Enum.map(results, fn m ->
%{n: m["n"], email: m["n"].properties["email"], name: m["n"].properties["name"]}
end)
Also Liked
Florin
you can use @kokolegorille’s example, and you can also use the recommendation from the Bolt.Sips Response docs and examples, pasting some samples below, for brevity:
iex» %Bolt.Sips.Response{results: results} = Bolt.Sips.query!(Bolt.Sips.conn(), "RETURN [10,11,21] AS arr")
iex» results
[%{"arr" => [10, 11, 21]}]
And of course, since Response implements the Enumerable protocol, you can easily use it for manipulating your results. Example:
Bolt.Sips.conn()
|> Bolt.Sips.query!("RETURN [10,11,21] AS arr")
|> Enum.reduce(0, &(Enum.sum(&1["arr"]) + &2))
# => 42
HTH
__
One of the main reasons the Response has a mix content, atoms and strings, is because we cannot control the response from the server, converting everything to atoms would obviously not be safe.
kokolegorille
Hello and welcome,
Probably the nicest way is to use
You need to remember results is a list. and your response mixes atoms and strings keys.
Florin
thank you @kokolegorille
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








