diff --git a/include/sqlite3.hrl b/include/sqlite3.hrl index f560401..0faf228 100644 --- a/include/sqlite3.hrl +++ b/include/sqlite3.hrl @@ -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()]} | {foreign_key, {[atom()], atom(), [atom()]}} | {unique, [atom()]}. +-type table_constraint() :: {primary_key, [atom()]} | {foreign_key, {[atom()], atom(), [atom()], string()}} | {unique, [atom()]}. -type table_constraints() :: table_constraint() | [table_constraint()]. -type table_info() :: [{column_id(), sql_type()} | {column_id(), sql_type(), column_constraints()}]. diff --git a/src/sqlite3_lib.erl b/src/sqlite3_lib.erl index 715d05a..f8afa67 100644 --- a/src/sqlite3_lib.erl +++ b/src/sqlite3_lib.erl @@ -376,14 +376,15 @@ table_constraint_sql(TableConstraint) -> {unique, Columns} -> ["UNIQUE(", map_intersperse(fun indexed_column_sql/1, Columns, ", "), ")"]; - {foreign_key, {Columns, Parent, ParentColumns}} -> + {foreign_key, {Columns, Parent, ParentColumns, Action}} -> ["FOREIGN KEY(", map_intersperse(fun indexed_column_sql/1, Columns, ", "), ") REFERENCES ", atom_to_list(Parent), "(", map_intersperse(fun indexed_column_sql/1, ParentColumns, ", "), - ")"]; + ")", + Action]; {raw, S} when is_list(S) -> S; _ when is_list(TableConstraint) -> map_intersperse(fun table_constraint_sql/1, TableConstraint, ", ")