Adding column names as option to map and foreach functions
This commit is contained in:
@@ -70,22 +70,35 @@ foreach(F, Sql, Connection) ->
|
||||
foreach_s(F, Statement).
|
||||
|
||||
%%
|
||||
foreach_s(F, Statement) ->
|
||||
foreach_s(F, Statement) when is_function(F, 1) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' ->
|
||||
ok;
|
||||
'$done' -> ok;
|
||||
Row when is_tuple(Row) ->
|
||||
F(Row),
|
||||
foreach_s(F, Statement)
|
||||
end.
|
||||
end;
|
||||
foreach_s(F, Statement) when is_function(F, 2) ->
|
||||
ColumnNames = column_names(Statement),
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> ok;
|
||||
Row when is_tuple(Row) ->
|
||||
F(ColumnNames, Row),
|
||||
foreach_s(F, Statement)
|
||||
end.
|
||||
|
||||
%%
|
||||
map_s(F, Statement) ->
|
||||
map_s(F, Statement) when is_function(F, 1) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' ->
|
||||
[];
|
||||
'$done' -> [];
|
||||
Row when is_tuple(Row) ->
|
||||
[F(Row) | map_s(F, Statement)]
|
||||
end;
|
||||
map_s(F, Statement) when is_function(F, 2) ->
|
||||
ColumnNames = column_names(Statement),
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> [];
|
||||
Row when is_tuple(Row) ->
|
||||
[F(ColumnNames, Row) | map_s(F, Statement)]
|
||||
end.
|
||||
|
||||
%%
|
||||
|
||||
Reference in New Issue
Block a user