Title says it all. If you’re querying postgres via epgsql, how are you handling responses?My postgres function returns JSON, however, as we know, it’s nested basically as result.rows[0].function_name…
I’ve been doing something like this but it just FEELS ugly.
case Result of
{ok, _Cols, []} ->
{error, not_found};
{ok, Cols, [Row|_]} ->
Values = tuple_to_list(Row),
case length(Cols) =:= length(Values) of
true ->
RowMap = maps:from_list(lists:zipwith(
fun({column, Name, _, _, _, _, _, _, _}, V) -> {Name, V};
(Name, V) when is_binary(Name) -> {Name, V};
(Name, V) -> {Name, V}
end,
Cols, Values))...
Has to be a cleaner way?