If we check the example for using Ecto fragments in the official docs, it says that in order to use a macro from another module, we need to import that module first. So, if we have the module with a coalesce/2
macro:
defmodule CustomFunctions do
defmacro coalesce(left, right) do
quote do
fragment("coalesce(?, ?)", unquote(left), unquote(right))
end
end
end
We need to import it in another module to use it:
import CustomFunctions
And after that, we could write the queries like this:
where(Post, [p], p.id in coalesce(3,5)
It works great as long as there are no name conflicts. But let's say, that for some reason, I am creating a few modules that will export only one macro called query
and obviously that won't take long until name conflicts start to appear. So I am wondering if it's possible to use the macro from above using its full name, like this:
require CustomFunctions
where(Post, [p], p.id in CustomFunctions.coalesce(3,5)
Obviously I tried it but it fails, saying that CustomFunctions.coalesce(3,5)
is not a proper query element.
So, is there a simple way to achieve something like that?