Support single constraints without lists
This commit is contained in:
@@ -373,8 +373,7 @@ hex_str_to_bin([X, Y | Tail], Acc) ->
|
|||||||
column_sql_for_create_table({Name, Type}) ->
|
column_sql_for_create_table({Name, Type}) ->
|
||||||
[atom_to_list(Name), " ", col_type_to_string(Type)];
|
[atom_to_list(Name), " ", col_type_to_string(Type)];
|
||||||
column_sql_for_create_table({Name, Type, Constraints}) ->
|
column_sql_for_create_table({Name, Type, Constraints}) ->
|
||||||
[atom_to_list(Name), " ", col_type_to_string(Type),
|
[atom_to_list(Name), " ", col_type_to_string(Type), " ", constraint_sql(Constraints)].
|
||||||
" " | map_intersperse(fun constraint_sql/1, Constraints, " ")].
|
|
||||||
|
|
||||||
-spec pk_constraint_sql(any()) -> iolist().
|
-spec pk_constraint_sql(any()) -> iolist().
|
||||||
pk_constraint_sql(Constraint) ->
|
pk_constraint_sql(Constraint) ->
|
||||||
@@ -392,7 +391,8 @@ constraint_sql(Constraint) ->
|
|||||||
{primary_key, C} -> ["PRIMARY KEY ", pk_constraint_sql(C)];
|
{primary_key, C} -> ["PRIMARY KEY ", pk_constraint_sql(C)];
|
||||||
unique -> "UNIQUE";
|
unique -> "UNIQUE";
|
||||||
not_null -> "NOT NULL";
|
not_null -> "NOT NULL";
|
||||||
{default, DefaultValue} -> ["DEFAULT ", value_to_sql(DefaultValue)]
|
{default, DefaultValue} -> ["DEFAULT ", value_to_sql(DefaultValue)];
|
||||||
|
List -> map_intersperse(fun constraint_sql/1, List, " ")
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec table_constraint_sql(any()) -> iolist().
|
-spec table_constraint_sql(any()) -> iolist().
|
||||||
|
|||||||
@@ -62,7 +62,11 @@ basic_functionality() ->
|
|||||||
Columns = ["id", "name", "age", "wage"],
|
Columns = ["id", "name", "age", "wage"],
|
||||||
AllRows = [{1, <<"abby">>, 20, 2000}, {2, <<"marge">>, 30, 2000}],
|
AllRows = [{1, <<"abby">>, 20, 2000}, {2, <<"marge">>, 30, 2000}],
|
||||||
AbbyOnly = [{1, <<"abby">>, 20, 2000}],
|
AbbyOnly = [{1, <<"abby">>, 20, 2000}],
|
||||||
TableInfo = [{id, integer, [{primary_key, [asc, autoincrement]}]}, {name, text, [not_null, unique]}, {age, integer}, {wage, integer}],
|
TableInfo = [{id, integer, [{primary_key, [asc, autoincrement]}]},
|
||||||
|
{name, text, [not_null, unique]},
|
||||||
|
{age, integer, not_null},
|
||||||
|
{wage, integer}],
|
||||||
|
TableInfo1 = lists:keyreplace(age, 1, TableInfo, {age, integer, [not_null]}),
|
||||||
drop_all_tables(ct),
|
drop_all_tables(ct),
|
||||||
?WARN_ERROR_MESSAGE,
|
?WARN_ERROR_MESSAGE,
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
@@ -76,7 +80,7 @@ basic_functionality() ->
|
|||||||
[user, sqlite_sequence],
|
[user, sqlite_sequence],
|
||||||
sqlite3:list_tables(ct)),
|
sqlite3:list_tables(ct)),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
TableInfo,
|
TableInfo1,
|
||||||
sqlite3:table_info(ct, user)),
|
sqlite3:table_info(ct, user)),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
{rowid, 1},
|
{rowid, 1},
|
||||||
|
|||||||
Reference in New Issue
Block a user