MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / op

Method op

lib/sqlalchemy/sql/operators.py:271–398  ·  view source on GitHub ↗

Produce a generic operator function. e.g.:: somecolumn.op("*")(5) produces:: somecolumn * 5 This function can also be used to make bitwise operators explicit. For example:: somecolumn.op("&")(0xFF) is a bitwise AND of the v

(
        self,
        opstring: str,
        precedence: int = 0,
        is_comparison: bool = False,
        return_type: Optional[
            Union[Type[TypeEngine[Any]], TypeEngine[Any]]
        ] = None,
        python_impl: Optional[Callable[..., Any]] = None,
        operator_class: OperatorClass = OperatorClass.BASE,
        visit_name: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

269 return self.operate(null_op, other)
270
271 def op(
272 self,
273 opstring: str,
274 precedence: int = 0,
275 is_comparison: bool = False,
276 return_type: Optional[
277 Union[Type[TypeEngine[Any]], TypeEngine[Any]]
278 ] = None,
279 python_impl: Optional[Callable[..., Any]] = None,
280 operator_class: OperatorClass = OperatorClass.BASE,
281 visit_name: Optional[str] = None,
282 ) -> Callable[[Any], Operators]:
283 """Produce a generic operator function.
284
285 e.g.::
286
287 somecolumn.op("*")(5)
288
289 produces::
290
291 somecolumn * 5
292
293 This function can also be used to make bitwise operators explicit. For
294 example::
295
296 somecolumn.op("&")(0xFF)
297
298 is a bitwise AND of the value in ``somecolumn``.
299
300 :param opstring: a string which will be output as the infix operator
301 between this element and the expression passed to the
302 generated function.
303
304 :param precedence: precedence which the database is expected to apply
305 to the operator in SQL expressions. This integer value acts as a hint
306 for the SQL compiler to know when explicit parenthesis should be
307 rendered around a particular operation. A lower number will cause the
308 expression to be parenthesized when applied against another operator
309 with higher precedence. The default value of ``0`` is lower than all
310 operators except for the comma (``,``) and ``AS`` operators. A value
311 of 100 will be higher or equal to all operators, and -100 will be
312 lower than or equal to all operators.
313
314 .. seealso::
315
316 :ref:`faq_sql_expression_op_parenthesis` - detailed description
317 of how the SQLAlchemy SQL compiler renders parenthesis
318
319 :param is_comparison: legacy; if True, the operator will be considered
320 as a "comparison" operator, that is which evaluates to a boolean
321 true/false value, like ``==``, ``>``, etc. This flag is provided
322 so that ORM relationships can establish that the operator is a
323 comparison operator when used in a custom join condition.
324
325 Using the ``is_comparison`` parameter is superseded by using the
326 :meth:`.Operators.bool_op` method instead; this more succinct
327 operator sets this parameter automatically, but also provides
328 correct :pep:`484` typing support as the returned object will

Callers 15

bool_opMethod · 0.95
l2_distanceMethod · 0.45
inner_productMethod · 0.45
cosine_distanceMethod · 0.45
opFunction · 0.45
_assert_and_overrideMethod · 0.45
_assert_add_overrideMethod · 0.45
__add__Method · 0.45
__and__Method · 0.45
__add__Method · 0.45

Calls 1

custom_opClass · 0.85

Tested by 15

_assert_and_overrideMethod · 0.36
_assert_add_overrideMethod · 0.36
__add__Method · 0.36
__and__Method · 0.36
__add__Method · 0.36
__and__Method · 0.36
__add__Method · 0.36
__and__Method · 0.36
__add__Method · 0.36
__and__Method · 0.36