I was wondering if there was any interest with adding common mathematical infix operators (+, -, *, and /) to the Query API.
I am interested in knowing if this is desired and would be accepted as a contribution.
It is a desired addition. The main obstacle would be proper type handling. We have to properly handle at least integers, floats and decimals.
In fact we had infix operators at some point, but when the typechecking was improved, they were dropped until reimplemented.
Yes, the best solution is to include an "abstract" type called :number and make sure Ecto's type system accepts :integer, :float and :decimal as numbers.
Where would I find sufficient test cases?
Where would one need to add the typechecking?
The type checking happens in Ecto.Query.Builder (compile time) and Ecto.Query.Planner (runtime). I am not sure what you mean by test cases. I believe they would need to be written by whoever is working on the feature.
@josevalim @michalmuskala said that there used to be infix in the codebase. I thought there might be test cases that already existed (in the git history) for the lower level modules, like Ecto.Query.Builder and Ecto.Query.Planner.
@isaacsanders I don't think they would be relevant at this point. They existed way before 1.0 and the builder and planner were quite different from today.
makes sense.
Hi, is anyone working on this issue? If not I would love to tackle it. (Or try my best at least :sweat_smile:)
@costaraphael nobody is working on it afaik, please go ahead!
Awesome, I should take a look at this week!
@josevalim is there anything left to do here or it can be closed?
We are missing documentation for the newly supported operators in Ecto.Query.API. @costaraphael could you please send a PR for that too? Thank you! :heart:
Whoops, I forgot about that :sweat_smile:
The docs should go to Ecto.Query.API, right?
Also, should I document for the new type usage (type(p.views + ^arg + ^other_arg, :decimal)) on the type/2 docs?
Jos茅 Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Director of R&D
Most helpful comment
@costaraphael nobody is working on it afaik, please go ahead!