Formatting
This commit is contained in:
@@ -51,7 +51,6 @@
|
||||
-type result() :: {'ok', pid()} | 'ignore' | {'error', any()}.
|
||||
|
||||
-spec start_link(atom()) -> result().
|
||||
|
||||
start_link(Db) ->
|
||||
open(Db, []).
|
||||
|
||||
@@ -751,14 +750,16 @@ exec(Port, {sql_bind_and_exec, SQL, Params}) ->
|
||||
wait_result(Port) ->
|
||||
receive
|
||||
{Port, error, Code, Reason} ->
|
||||
error_logger:error_msg("sqlite3 driver error: ~s~n", [Reason]),
|
||||
error_logger:error_msg("sqlite3 driver error: ~s~n",
|
||||
[Reason]),
|
||||
% ?dbg("Error: ~p~n", [Reason]),
|
||||
{error, Code, Reason};
|
||||
{Port, Reply} ->
|
||||
% ?dbg("Reply: ~p~n", [Reply]),
|
||||
Reply;
|
||||
{'EXIT', Port, Reason} ->
|
||||
error_logger:error_msg("sqlite3 driver port closed with reason ~p~n", [Reason]),
|
||||
error_logger:error_msg("sqlite3 driver port closed with reason ~p~n",
|
||||
[Reason]),
|
||||
% ?dbg("Error: ~p~n", [Reason]),
|
||||
{error, -1, Reason}
|
||||
end.
|
||||
|
||||
@@ -356,7 +356,8 @@ sql_number(NumberStr) ->
|
||||
|
||||
-spec sql_string(string()) -> binary().
|
||||
sql_string(StringWithEscapedQuotes) ->
|
||||
Res1 = re:replace(StringWithEscapedQuotes, "''", "'", [global, {return, binary}]),
|
||||
Res1 = re:replace(StringWithEscapedQuotes, "''", "'",
|
||||
[global, {return, binary}]),
|
||||
binary_part(Res1, 0, byte_size(Res1) - 1).
|
||||
|
||||
-spec sql_blob(string()) -> binary().
|
||||
@@ -386,8 +387,12 @@ constraint_sql(Constraint) ->
|
||||
-spec table_constraint_sql(any()) -> iolist().
|
||||
table_constraint_sql(TableConstraint) ->
|
||||
case TableConstraint of
|
||||
{primary_key, Columns} -> ["PRIMARY KEY(", map_intersperse(fun indexed_column_sql/1, Columns, ", "), ")"];
|
||||
{unique, Columns} -> ["UNIQUE(", map_intersperse(fun indexed_column_sql/1, Columns, ", "), ")"]
|
||||
{primary_key, Columns} ->
|
||||
["PRIMARY KEY(",
|
||||
map_intersperse(fun indexed_column_sql/1, Columns, ", "), ")"];
|
||||
{unique, Columns} ->
|
||||
["UNIQUE(",
|
||||
map_intersperse(fun indexed_column_sql/1, Columns, ", "), ")"]
|
||||
%% TODO: foreign key
|
||||
end.
|
||||
|
||||
@@ -409,8 +414,8 @@ indexed_column_sql(ColumnName) -> atom_to_list(ColumnName).
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(FLAT(X), iolist_to_binary(X)).
|
||||
-define(assertFlat(Expected, Value), ?assertEqual(iolist_to_binary(Expected), iolist_to_binary(Value))).
|
||||
-define(assertFlat(Expected, Value),
|
||||
?assertEqual(iolist_to_binary(Expected), iolist_to_binary(Value))).
|
||||
|
||||
quote_test() ->
|
||||
?assertFlat("'abc'", value_to_sql("abc")),
|
||||
@@ -422,7 +427,9 @@ create_table_sql_test() ->
|
||||
create_table_sql(user, [{id, integer, [primary_key]}, {name, text}])),
|
||||
?assertFlat(
|
||||
"CREATE TABLE user (id INTEGER, name TEXT, PRIMARY KEY(id));",
|
||||
create_table_sql(user, [{id, integer}, {name, text}], [{primary_key, [id]}])).
|
||||
create_table_sql(user,
|
||||
[{id, integer}, {name, text}],
|
||||
[{primary_key, [id]}])).
|
||||
|
||||
update_sql_test() ->
|
||||
?assertFlat(
|
||||
|
||||
Reference in New Issue
Block a user