[ Phoenix Elixir ] Fragments in Ecto Query
Ecto query provide query DSL on Elixir for retrieve & manipulate data from database. It allows a limited set of expressions inside queries but you can use “fragments” for inject spesific SQL for the query. For example if you need to use “lower” function on your query:
from p in Post, where: is_nil(p.published_at) and fragment("lower(?)", p.title) == ^title
or you need to query by compare MONTH on the DATE type data.
from u in Post, where: fragment("Extract(month from ?)", u.date) == ^float_month order_by: [desc: :date], select: u