Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé
Classe « Operators »

Méthode sqlalchemy.Operators.op

Signature de la méthode op

def op(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) -> 'Callable[[Any], Operators]' 

Description

help(Operators.op)

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 value in ``somecolumn``.

:param opstring: a string which will be output as the infix operator
  between this element and the expression passed to the
  generated function.

:param precedence: precedence which the database is expected to apply
 to the operator in SQL expressions. This integer value acts as a hint
 for the SQL compiler to know when explicit parenthesis should be
 rendered around a particular operation. A lower number will cause the
 expression to be parenthesized when applied against another operator
 with higher precedence. The default value of ``0`` is lower than all
 operators except for the comma (``,``) and ``AS`` operators. A value
 of 100 will be higher or equal to all operators, and -100 will be
 lower than or equal to all operators.

 .. seealso::

    :ref:`faq_sql_expression_op_parenthesis` - detailed description
    of how the SQLAlchemy SQL compiler renders parenthesis

:param is_comparison: legacy; if True, the operator will be considered
 as a "comparison" operator, that is which evaluates to a boolean
 true/false value, like ``==``, ``>``, etc.  This flag is provided
 so that ORM relationships can establish that the operator is a
 comparison operator when used in a custom join condition.

 Using the ``is_comparison`` parameter is superseded by using the
 :meth:`.Operators.bool_op` method instead;  this more succinct
 operator sets this parameter automatically, but also provides
 correct :pep:`484` typing support as the returned object will
 express a "boolean" datatype, i.e. ``BinaryExpression[bool]``.

:param return_type: a :class:`.TypeEngine` class or object that will
  force the return type of an expression produced by this operator
  to be of that type.   By default, operators that specify
  :paramref:`.Operators.op.is_comparison` will resolve to
  :class:`.Boolean`, and those that do not will be of the same
  type as the left-hand operand.

:param python_impl: an optional Python function that can evaluate
 two Python values in the same way as this operator works when
 run on the database server.  Useful for in-Python SQL expression
 evaluation functions, such as for ORM hybrid attributes, and the
 ORM "evaluator" used to match objects in a session after a multi-row
 update or delete.

 e.g.::

    >>> expr = column("x").op("+", python_impl=lambda a, b: a + b)("y")

 The operator for the above expression will also work for non-SQL
 left and right objects::

    >>> expr.operator(5, 10)
    15

 .. versionadded:: 2.0


.. seealso::

    :meth:`.Operators.bool_op`

    :ref:`types_operators`

    :ref:`relationship_custom_operator`



Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé