Replaced use of intersperse with map_intersperse
This commit is contained in:
@@ -92,8 +92,7 @@ value_to_sql(X) ->
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_value_sql/1::(any()) -> string()).
|
-spec(write_value_sql/1::(any()) -> string()).
|
||||||
write_value_sql(Values) ->
|
write_value_sql(Values) ->
|
||||||
StrValues = lists:map(fun value_to_sql/1, Values),
|
map_intersperse(fun value_to_sql/1, Values, ",").
|
||||||
intersperse(StrValues, ",").
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec write_col_sql([atom()]) -> string()
|
%% @spec write_col_sql([atom()]) -> string()
|
||||||
@@ -102,10 +101,7 @@ write_value_sql(Values) ->
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_col_sql/1::([atom()]) -> string()).
|
-spec(write_col_sql/1::([atom()]) -> string()).
|
||||||
write_col_sql(Cols) ->
|
write_col_sql(Cols) ->
|
||||||
StrCols = lists:map(fun(X) ->
|
map_intersperse(fun atom_to_list/1, Cols, ",").
|
||||||
atom_to_list(X)
|
|
||||||
end, Cols),
|
|
||||||
intersperse(StrCols, ",").
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec replace (String) -> string ()
|
%% @spec replace (String) -> string ()
|
||||||
@@ -141,14 +137,11 @@ escape(IoData) -> re:replace(IoData, "'", "''", [global]).
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (update_set_sql/1::(any ()) -> string ()).
|
-spec (update_set_sql/1::(any ()) -> string ()).
|
||||||
update_set_sql (Data) ->
|
update_set_sql (Data) ->
|
||||||
Set = lists:map (fun
|
ColValueToSqlFun =
|
||||||
({Col, Value}) when is_list(Value) ->
|
fun({Col, Value}) ->
|
||||||
[atom_to_list (Col), " = ", $", replace(Value), $"];
|
|
||||||
({Col, Value}) ->
|
|
||||||
[atom_to_list (Col), " = ", value_to_sql(Value)]
|
[atom_to_list (Col), " = ", value_to_sql(Value)]
|
||||||
end,
|
end,
|
||||||
Data),
|
map_intersperse(ColValueToSqlFun, Data, ", ").
|
||||||
intersperse(Set, ", ").
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec read_cols_sql (Columns::[atom ()]) -> string ()
|
%% @spec read_cols_sql (Columns::[atom ()]) -> string ()
|
||||||
@@ -158,8 +151,7 @@ update_set_sql (Data) ->
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (read_cols_sql/1::([atom ()]) -> string ()).
|
-spec (read_cols_sql/1::([atom ()]) -> string ()).
|
||||||
read_cols_sql (Columns) ->
|
read_cols_sql (Columns) ->
|
||||||
intersperse(
|
map_intersperse(fun atom_to_list/1, Columns, ", ").
|
||||||
lists:map(fun atom_to_list/1, Columns), ", ").
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @spec create_table_sql(Tbl, [{ColName, Type}]) -> string()
|
%% @spec create_table_sql(Tbl, [{ColName, Type}]) -> string()
|
||||||
@@ -173,10 +165,10 @@ read_cols_sql (Columns) ->
|
|||||||
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
||||||
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
|
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
|
||||||
Start = ["(", atom_to_list(ColName), " ", sqlite3_lib:col_type(Type), " PRIMARY KEY, "],
|
Start = ["(", atom_to_list(ColName), " ", sqlite3_lib:col_type(Type), " PRIMARY KEY, "],
|
||||||
End = [intersperse(
|
End = [map_intersperse(
|
||||||
lists:map(fun({Name0, Type0}) ->
|
fun({Name0, Type0}) ->
|
||||||
[atom_to_list(Name0), " ", sqlite3_lib:col_type(Type0)]
|
[atom_to_list(Name0), " ", sqlite3_lib:col_type(Type0)]
|
||||||
end, Tl), ", "), ");"],
|
end, Tl, ", "), ");"],
|
||||||
[CT, Start, End].
|
[CT, Start, End].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -271,6 +263,7 @@ drop_table(Tbl) ->
|
|||||||
|
|
||||||
%% @doc Works like string:join for iolists
|
%% @doc Works like string:join for iolists
|
||||||
|
|
||||||
intersperse([], _Sep) -> [];
|
-spec map_intersperse(fun((X) -> Z), [X], Y) -> [Z | Y].
|
||||||
intersperse([Elem], _Sep) -> [Elem];
|
map_intersperse(_Fun, [], _Sep) -> [];
|
||||||
intersperse([Head | Tail], Sep) -> [Head, Sep | intersperse(Tail, Sep)].
|
map_intersperse(Fun, [Elem], _Sep) -> [Fun(Elem)];
|
||||||
|
map_intersperse(Fun, [Head | Tail], Sep) -> [Fun(Head), Sep | map_intersperse(Fun, Tail, Sep)].
|
||||||
|
|||||||
Reference in New Issue
Block a user