Comparators¶
The syntax where={'id': 123}
works well for =
conditions but breaks down for other operators. For that purpose, jardin offers comparators.
For example
>>> from jardin.comparators import *
>>> User.count(where={'created_at': gt(datetime.utcnow() - timedelta(day=1))})
# SELECT COUNT(*) FROM users WHERE created_at > '2018-04-29 12:00:00';
All comparators¶
Comparator | Operator | Example | Result |
---|---|---|---|
lt |
< | {'n': lt(3)} |
WHERE n < 3 |
leq |
<= | {'n': leq(3)} |
WHERE n <= 3 |
gt |
> | {'n': gt(3)} |
WHERE n > 3 |
geq |
<= | {'n': geq(3)} |
WHERE n >= 3 |
not_null |
{'n': not_null()} |
WHERE n IS NOT NULL |
|
not_in |
{'n': not_in([1, 2])} |
WHERE n IS NOT IN (1, 2) |