I know how I can use dynamic fields and values into Ecto query, for example:
field = :age
value = 20
Ecto.Query.where(App.User, [x], field(x, ^field) < ^value)
But, it is possible to define the operator (in this example <) dynamically? and how?
I have tried it with fragment and interpolated string:
operator = ">"
Ecto.Query.where(App.User, [x], fragment("? #{operator} ?", field(x, ^field), ^value))
but it raises the exception: Ecto.Query.CompileError) to prevent SQL injection attacks, fragment(...) does not allow strings...