Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

Query OR syntax #134

Closed Jaymon closed 1 year ago

Jaymon commented 3 years ago

Would something like this work:

Orm.query.eq_foo("<VAL>").or_start().in_bar([1, 2]).eq_bar(None).or_stop().eq_che("<VAL2>")

Would result in a query like:

WHERE
  foo = '<VAL>
AND
  (bar IN (1, 2) OR bar is NULL)
AND
  che = '<VAL2>'

Or, maybe it could be even more clever and just infer:

Orm.query.eq_foo("<VAL>").in_bar([1, 2]).or().eq_bar(None).eq_che("<VAL2>")

I think that could work, the idea would be that the .or() just combines the last set WHERE value and wraps it in parens with whatever comes next. If you do another .or() then it would just append that on again, so you can have whole chains of (... OR ... OR ...) statement fragments. I actually think that might work.

This would also give a viable path for #123 without having to implement anything that looks at every value passed into the in_* method