Added foreign_key table constraint
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
-type column_constraint() :: non_null | primary_key | {primary_key, pk_constraints()}
|
||||
| unique | {default, sql_value()}.
|
||||
-type column_constraints() :: column_constraint() | [column_constraint()].
|
||||
-type table_constraint() :: {primary_key, [atom()]} | {unique, [atom()]}.
|
||||
-type table_constraint() :: {primary_key, [atom()]} | {foreign_key, {[atom()], atom(), [atom()]}} | {unique, [atom()]}.
|
||||
-type table_constraints() :: table_constraint() | [table_constraint()].
|
||||
-type table_info() :: [{column_id(), sql_type()} | {column_id(), sql_type(), column_constraints()}].
|
||||
|
||||
|
||||
@@ -376,7 +376,14 @@ table_constraint_sql(TableConstraint) ->
|
||||
{unique, Columns} ->
|
||||
["UNIQUE(",
|
||||
map_intersperse(fun indexed_column_sql/1, Columns, ", "), ")"];
|
||||
%% TODO: foreign key
|
||||
{foreign_key, {Columns, Parent, ParentColumns}} ->
|
||||
["FOREIGN KEY(",
|
||||
map_intersperse(fun indexed_column_sql/1, Columns, ", "),
|
||||
") REFERENCES ",
|
||||
atom_to_list(Parent),
|
||||
"(",
|
||||
map_intersperse(fun indexed_column_sql/1, ParentColumns, ", "),
|
||||
")"];
|
||||
{raw, S} when is_list(S) -> S;
|
||||
_ when is_list(TableConstraint) ->
|
||||
map_intersperse(fun table_constraint_sql/1, TableConstraint, ", ")
|
||||
|
||||
Reference in New Issue
Block a user