postgresql - Elixir - Creating JSON object from 2 collections -


i'm using postgrex in elixir, , when returns query results, returns them in following struct format:

%{columns: ["id", "email", "name"], command: :select, num_rows: 2, rows: [{1, "me@me.com", "bobbly long"}, {6, "email@tts.me", "woll smoth"}]} 

it should noted using postgrex directly without ecto.

the columns (table headers) returned collection, results (rows) returned list of tuples. (which seems odd, large).

i'm trying find best way programmatically create json objects each result in json key column title , json value corresponding value tuple.

i've tried creating maps both, merging , serialising json objects seems there should easier/better way of doing this.

has dealt before? best way of creating json object separate collection , tuple?

something should work:

result = postgrex.query!(...)  enum.map(result.rows, fn row ->   enum.zip(result.columns, tuple.to_list(row))   |> enum.into(%{})   |> json.encode end) 

this result in list of json objects each row in resultset json object.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -