3 ms·
It depends on what you mean by extending Ecto. I've read bits of the source code to better understand what commands are doing, and you're right you can't use a
by iudqnolq 5y ago
It depends on what you mean by extending Ecto.
I've read bits of the source code to better understand what commands are doing, and you're right you can't use an IDE to jump from the public api to the internal implementation. However, the project has put a lot of work into an extremely clear internal naming convention, so you can just go to the implementation directory and grep for the public api name.
If you mean writing your own command that composes like the builtin ones, that's extremely easy. Often you can do it with just a plain function, and rarely you need a macro. Suppose you have something like this (haven't written elixir in a while, syntax may be slightly wrong)
def where_admin_over(q, age) do:
where(q, [u], u.age > ^age and u.is_admin)
end
def foo do
from(User)
|> where_admin_over(18)
|> where([u], u.country == "de")
|> Repo.all()
end
It's also quite easy to make that custom command run raw sql.