Helper function - "proplistize"

11 visningar
Hoppa till det första olästa meddelandet

David Welton

oläst,
1 apr. 2015 06:37:552015-04-01
till epg...@googlegroups.com
It would take a result like {ok, Columns, Result}, and map the Result
with the Column names, giving you a list of proplists.

[[{id, 1}, {name, "Bob"}],
[{id, 2}, {name, "Sally"}]]

For instance.

Thoughts?

--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/

Cobus Carstens

oläst,
2 apr. 2015 00:23:162015-04-02
till epg...@googlegroups.com
I have the following function which I use:

%%
%% @doc Return a list of proplists representing the Columns and Rows supplied
%%
-spec transduce(Colums::[#column{}], Rows::[tuple()]) ->
    [list({binary(), any()})].

transduce(_Colums, []) ->
     [];
transduce(Columns, Rows) ->
    ColumnNames = [ C#column.name || C <- Columns ],
    [ lists:zip(ColumnNames, erlang:tuple_to_list(Row)) || Row <- Rows].

David Welton

oläst,
10 apr. 2015 06:39:502015-04-10
till Cobus Carstens, epg...@googlegroups.com
Hi,

Thanks!

What about turning the column names into atoms?  It'd be a convenience in the 99% of cases when it works with no problems...


--
You received this message because you are subscribed to the Google Groups "Erlang epgsql Postgres driver use and development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to epgsql+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Welton

oläst,
23 apr. 2015 09:11:592015-04-23
till epg...@googlegroups.com
I pushed this to the to_proplist branch, and do turn column names into atoms.

I'll merge it into devel in a bit, unless there are objections.

David Welton

oläst,
23 apr. 2015 16:06:472015-04-23
till epg...@googlegroups.com
On Thu, Apr 23, 2015 at 5:22 PM, Cobus Carstens
<cobus.c...@gmail.com> wrote:
>
> Personally I am not a fan of converting the column name to an atom, mostly because it can be something like 'avg((foo + bar) / baz)'.

pgapp:equery("select avg(foo) + 1 from bar", []).
{ok,[{column,<<"?column?">>,float8,8,-1,1}],[{1.0}]}

pgapp:equery("select avg(foo) + 1 as avg from bar", []).
{ok,[{column,<<"avg">>,float8,8,-1,1}],[{1.0}]}

You get the "?column?" string if it can't decide on a name. Which
does not make for a very good atom, but... you can easily use 'as' if
you want a nice name.
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden