|
1 | | -from datetime import date, datetime |
2 | | -from decimal import Decimal |
3 | | - |
4 | | -from cnct.rql.utils import parse_kwargs |
| 1 | +from cnct.rql.utils import parse_kwargs, to_rql_value |
5 | 2 |
|
6 | 3 |
|
7 | 4 | COMP = ('eq', 'ne', 'lt', 'le', 'gt', 'ge') |
@@ -225,31 +222,15 @@ def empty(self, value): |
225 | 222 |
|
226 | 223 | def _bin(self, op, value): |
227 | 224 | self._field = '.'.join(self._path) |
228 | | - actual_value = None |
229 | | - if isinstance(value, str): |
230 | | - actual_value = value |
231 | | - elif isinstance(value, bool): |
232 | | - actual_value = 'true' if value else 'false' |
233 | | - elif isinstance(value, (int, float, Decimal)): |
234 | | - actual_value = str(value) |
235 | | - elif isinstance(value, (date, datetime)): |
236 | | - actual_value = value.isoformat() |
237 | | - else: |
238 | | - raise TypeError(f"the `{op}` operator doesn't support the {type(value)} type.") |
239 | | - |
240 | | - self.expr = f'{op}({self._field},{actual_value})' |
| 225 | + value = to_rql_value(op, value) |
| 226 | + self.expr = f'{op}({self._field},{value})' |
241 | 227 | return self |
242 | 228 |
|
243 | 229 | def _list(self, op, value): |
244 | 230 | self._field = '.'.join(self._path) |
245 | | - actual_value = None |
246 | | - if isinstance(value, (list, tuple)): |
247 | | - actual_value = ','.join(value) |
248 | | - if actual_value: |
249 | | - self.expr = f'{op}({self._field},({actual_value}))' |
250 | | - return self |
251 | | - |
252 | | - raise TypeError(f"the `{op}` operator doesn't support the {type(value)} type.") |
| 231 | + value = to_rql_value(op, value) |
| 232 | + self.expr = f'{op}({self._field},({value}))' |
| 233 | + return self |
253 | 234 |
|
254 | 235 | def _bool(self, expr, value): |
255 | 236 | self._field = '.'.join(self._path) |
|
0 commit comments