Elixir 未使用的宏,编译器警告
我在编译器中遇到了一个奇怪的问题——它声称我的宏没有使用,尽管我在同一个模块中调用它。它可能与在where语句中使用它有关,但最终我想这应该不是问题。有什么想法吗Elixir 未使用的宏,编译器警告,elixir,ecto,Elixir,Ecto,我在编译器中遇到了一个奇怪的问题——它声称我的宏没有使用,尽管我在同一个模块中调用它。它可能与在where语句中使用它有关,但最终我想这应该不是问题。有什么想法吗 defmoduledo 反宏观聚合(左、右)do 引述 片段(“合并(?)”,不引用(左),不引用(右)) 结束 结束 def remove(timestamp\\Timex.now)do 模式 |>其中([p],联合(p.time,^timestamp)Repo.delete_all(返回:select_all(模式)) 结束 结束
defmoduledo
反宏观聚合(左、右)do
引述
片段(“合并(?)”,不引用(左),不引用(右))
结束
结束
def remove(timestamp\\Timex.now)do
模式
|>其中([p],联合(p.time,^timestamp)<^timestamp)
|>Repo.delete_all(返回:select_all(模式))
结束
结束
这是因为您没有使用定义的宏。您正在使用Ha!好消息:)我确实在这里导入了exto.Query
,但没有粘贴它。谢谢。根据我的经验,在你熟练掌握一门语言之前,你应该总是用前导的my
来命名你的变量/函数。它可以防止像你一样头疼。问题是我花了很多时间使用Exto 2.0,升级后出现了问题;)
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