Open margaretselzer opened 1 month ago
This is in the works already. The optional-no-dynamic
branch provides a much more flexible way of composing conditions dynamically.
Your example would look like this:
where((foo.id == 1 and dynamic(someCondition, foo.pos == 133)) or dynamic(someOtherCondition, foo.name == "yay"))
Looks really good. :-)
It's only the branch name that is a bit curious for a branch that implements the function dynamic()
:)
Thanks for the feedback, and yes, I know...
The name was about removing the old-style dynamic. But then it developed its own dynamic :-)
Right now
dynamic_where()
only supports adding conditions in aAND
relationship. E.g. according to the examplewill produce the where-clause of
WHERE (foo.id = 1) AND (foo.name = 'txt')
without the possibility to use for example theOR
operator or group sub-expressions.A more flexible where-clause builder capability is needed so that more complex logical expressions could be dynamically built.
E.g.:
If all conditions are met, the above should yield:
WHERE ((foo.id = 1) AND (foo.pos = 133)) OR (foo.name = 'yay')
.My real-life need is that I have to select from a table rows where I have a match on label AND a position but the number of these label-position pairs is dynamically changing, In some cases I have just one pair, in some cases I have several and I need to return all matching rows. With the current
dynamic_where
it is not possible as I need anOR
between all my(label = "labelX" AND pos = Y)
sub-expressions.