未使用的宏,编译器警告
Unused macro, compiler warning
我遇到了编译器的奇怪问题 - 它声称我的宏未被使用,尽管我在同一个模块中调用它。它可能与在 where 语句中使用它有关,但我想最终这应该不是问题。有什么想法吗? ;)
defmodule Module do
defmacrop coalesce(left, right) do
quote do
fragment("COALESCE(?, ?)", unquote(left), unquote(right))
end
end
def remove(timestamp \ Timex.now) do
Schema
|> where([p], coalesce(p.time, ^timestamp) < ^timestamp)
|> Repo.delete_all(returning: select_all(Schema))
end
end
那是因为你没有使用你定义的宏。您正在使用 Ecto.Query.API.coalesce
我遇到了编译器的奇怪问题 - 它声称我的宏未被使用,尽管我在同一个模块中调用它。它可能与在 where 语句中使用它有关,但我想最终这应该不是问题。有什么想法吗? ;)
defmodule Module do
defmacrop coalesce(left, right) do
quote do
fragment("COALESCE(?, ?)", unquote(left), unquote(right))
end
end
def remove(timestamp \ Timex.now) do
Schema
|> where([p], coalesce(p.time, ^timestamp) < ^timestamp)
|> Repo.delete_all(returning: select_all(Schema))
end
end
那是因为你没有使用你定义的宏。您正在使用 Ecto.Query.API.coalesce