ostafen/clover

Add support for criteria involving operations between fields

ostafen opened this issue · 2 comments

Currently, clover db only supports building criteria where you compare a field with a value, like the one in the following example:

db.Query("myCollection").Where(c.Field("myField").Eq(1))

Naturally, there are several contexts where one may need to express condition where you compare fields of the same document. For example you may want to select documents satisfying a condition such as myField1 > myField2.

This could be integrated inside clover in the following way:

db.Query("myCollection").Where(c.Field("myField1").Gt("$myField2"))

where the special syntax $myField2 tells clover to extract the value to use for comparison from the document field named myField2.

Suggestions and feedback about alternative ways to accomplish this are welcome :=)

Nice idea.
I think this kind of syntax explains the intent better.

db.Query("myCollection").Where(c.Field("myField1").Gt(c.Field("myField2"))

Yes, it is the best alternative :)
I thought about this, and, to tell the truth, it is also the most natural way.
But maybe, it could be useful to support the dollar syntax, which can be faster to use