Skip to content

Commit 66431c7

Browse files
authored
Reword comments about TEXT_DATETIME pseudo-type to remove HACK warnings. (#147)
1 parent 20c5097 commit 66431c7

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/sqlite_db_connection/query.ex

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,10 @@ defimpl DBConnection.Query, for: Sqlite.DbConnection.Query do
135135
{String.to_integer(hr), String.to_integer(mi), String.to_integer(se), fr}
136136
end
137137

138-
# HACK: We have to do a special conversion if the user is trying to cast to
139-
# a DATETIME type. Sqlitex cannot determine that the type of the cast is a
140-
# datetime value because datetime defaults to an integer type in SQLite.
141-
# Thus, we cast the value to a TEXT_DATETIME pseudo-type to preserve the
142-
# datetime string. Then when we get here, we convert the string to an Ecto
143-
# datetime tuple if it looks like a cast was attempted.
138+
# We use a special conversion for when the user is trying to cast to a
139+
# DATETIME type. We introduce a TEXT_DATETIME psudo-type to preserve the
140+
# datetime string. When we get here, we look for a CAST function as a signal
141+
# to convert that back to Elixir date types.
144142
defp cast_any_datetimes(row) do
145143
Enum.map row, fn {value, column_name} ->
146144
if String.contains?(column_name, "CAST (") && String.contains?(column_name, "TEXT_DATE") do

lib/sqlite_ecto/connection.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,16 @@ if Code.ensure_loaded?(Sqlitex.Server) do
534534
defp ecto_to_db(:binary), do: "BLOB"
535535
defp ecto_to_db(:float), do: "NUMERIC"
536536
defp ecto_to_db(:string), do: "TEXT"
537-
defp ecto_to_db(:utc_datetime), do: "TEXT_DATETIME" # HACK see: cast_any_datetimes/1
538-
defp ecto_to_db(:naive_datetime), do: "TEXT_DATETIME" # HACK see: cast_any_datetimes/1
537+
defp ecto_to_db(:utc_datetime), do: "TEXT_DATETIME" # see below
538+
defp ecto_to_db(:naive_datetime), do: "TEXT_DATETIME" # see below
539539
defp ecto_to_db(:map), do: "TEXT"
540540
defp ecto_to_db(other), do: other |> Atom.to_string |> String.upcase
541541

542+
# We use a special conversion for when the user is trying to cast to a
543+
# DATETIME type. We introduce a TEXT_DATETIME psudo-type to preserve the
544+
# datetime string. When we get here, we look for a CAST function as a signal
545+
# to convert that back to Elixir date types.
546+
542547
defp create_names(%{prefix: prefix, sources: sources}, stmt) do
543548
create_names(prefix, sources, 0, tuple_size(sources), stmt)
544549
|> prohibit_subquery_if_necessary(stmt)

0 commit comments

Comments
 (0)