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}) ->
|
||||
[atom_to_list(Name), " ", col_type_to_string(Type)];
|
||||
column_sql_for_create_table({Name, Type, Constraints}) ->
|
||||
[atom_to_list(Name), " ", col_type_to_string(Type),
|
||||
" " | map_intersperse(fun constraint_sql/1, Constraints, " ")].
|
||||
[atom_to_list(Name), " ", col_type_to_string(Type), " ", constraint_sql(Constraints)].
|
||||
|
||||
-spec pk_constraint_sql(any()) -> iolist().
|
||||
pk_constraint_sql(Constraint) ->
|
||||
@@ -392,7 +391,8 @@ constraint_sql(Constraint) ->
|
||||
{primary_key, C} -> ["PRIMARY KEY ", pk_constraint_sql(C)];
|
||||
unique -> "UNIQUE";
|
||||
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.
|
||||
|
||||
-spec table_constraint_sql(any()) -> iolist().
|
||||
|
||||
@@ -62,7 +62,11 @@ basic_functionality() ->
|
||||
Columns = ["id", "name", "age", "wage"],
|
||||
AllRows = [{1, <<"abby">>, 20, 2000}, {2, <<"marge">>, 30, 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),
|
||||
?WARN_ERROR_MESSAGE,
|
||||
?assertEqual(
|
||||
@@ -76,7 +80,7 @@ basic_functionality() ->
|
||||
[user, sqlite_sequence],
|
||||
sqlite3:list_tables(ct)),
|
||||
?assertEqual(
|
||||
TableInfo,
|
||||
TableInfo1,
|
||||
sqlite3:table_info(ct, user)),
|
||||
?assertEqual(
|
||||
{rowid, 1},
|
||||
|
||||
Reference in New Issue
Block a user