Skip to content

Commit c0eaada

Browse files
committed
Simplify default_expr to no longer consider type
1 parent b8ef1c0 commit c0eaada

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do
16911691
check = Keyword.get(opts, :check)
16921692

16931693
[
1694-
default_expr(default, type),
1694+
default_expr(default),
16951695
null_expr(null),
16961696
collate_expr(collate),
16971697
check_expr(check),
@@ -1715,48 +1715,30 @@ defmodule Ecto.Adapters.SQLite3.Connection do
17151715
defp null_expr(true), do: " NULL"
17161716
defp null_expr(_), do: []
17171717

1718-
defp default_expr({:ok, nil}, _type) do
1718+
defp default_expr({:ok, nil}) do
17191719
" DEFAULT NULL"
17201720
end
17211721

1722-
defp default_expr({:ok, literal}, _type) when is_binary(literal) do
1723-
[
1724-
" DEFAULT '",
1725-
escape_string(literal),
1726-
?'
1727-
]
1722+
defp default_expr({:ok, literal}) when is_binary(literal) do
1723+
[" DEFAULT '", escape_string(literal), ?']
17281724
end
17291725

1730-
defp default_expr({:ok, literal}, _type)
1731-
when is_number(literal) or is_boolean(literal) do
1732-
[
1733-
" DEFAULT ",
1734-
to_string(literal)
1735-
]
1726+
defp default_expr({:ok, literal}) when is_number(literal) or is_boolean(literal) do
1727+
[" DEFAULT ", to_string(literal)]
17361728
end
17371729

1738-
defp default_expr({:ok, {:fragment, expression}}, _type) do
1739-
[
1740-
" DEFAULT ",
1741-
expression
1742-
]
1730+
defp default_expr({:ok, {:fragment, expression}}) do
1731+
[" DEFAULT ", expression]
17431732
end
17441733

1745-
defp default_expr({:ok, value}, _type) when is_map(value) or is_list(value) do
1734+
defp default_expr({:ok, value}) when is_map(value) or is_list(value) do
17461735
library = Application.get_env(:ecto_sqlite3, :json_library, Jason)
17471736
expression = IO.iodata_to_binary(library.encode_to_iodata!(value))
17481737

1749-
[
1750-
" DEFAULT ",
1751-
?(,
1752-
?',
1753-
escape_string(expression),
1754-
?',
1755-
?)
1756-
]
1738+
[" DEFAULT ('", escape_string(expression), "')"]
17571739
end
17581740

1759-
defp default_expr(:error, _type), do: []
1741+
defp default_expr(:error), do: []
17601742

17611743
defp index_expr(literal) when is_binary(literal), do: literal
17621744
defp index_expr(literal), do: quote_name(literal)

0 commit comments

Comments
 (0)