Vous êtes un professionnel et vous avez besoin d'une formation ?
Machine Learning
avec Scikit-Learn
Voir le programme détaillé
Module « sqlalchemy.orm »
Classe « PropComparator »
Informations générales
Héritage
builtins.object
Operators
ColumnOperators
builtins.object
Generic
builtins.object
TypingOnly
builtins.object
TypingOnly
builtins.object
Operators
ColumnOperators
builtins.object
Generic
SQLCoreOperations
SQLORMOperations
PropComparator
Définition
class PropComparator(SQLORMOperations, Generic, ColumnOperators):
help(PropComparator)
Defines SQL operations for ORM mapped attributes.
SQLAlchemy allows for operators to
be redefined at both the Core and ORM level. :class:`.PropComparator`
is the base class of operator redefinition for ORM-level operations,
including those of :class:`.ColumnProperty`,
:class:`.Relationship`, and :class:`.Composite`.
User-defined subclasses of :class:`.PropComparator` may be created. The
built-in Python comparison and math operator methods, such as
:meth:`.operators.ColumnOperators.__eq__`,
:meth:`.operators.ColumnOperators.__lt__`, and
:meth:`.operators.ColumnOperators.__add__`, can be overridden to provide
new operator behavior. The custom :class:`.PropComparator` is passed to
the :class:`.MapperProperty` instance via the ``comparator_factory``
argument. In each case,
the appropriate subclass of :class:`.PropComparator` should be used::
# definition of custom PropComparator subclasses
from sqlalchemy.orm.properties import (
ColumnProperty,
Composite,
Relationship,
)
class MyColumnComparator(ColumnProperty.Comparator):
def __eq__(self, other):
return self.__clause_element__() == other
class MyRelationshipComparator(Relationship.Comparator):
def any(self, expression):
"define the 'any' operation"
# ...
class MyCompositeComparator(Composite.Comparator):
def __gt__(self, other):
"redefine the 'greater than' operation"
return sql.and_(
*[
a > b
for a, b in zip(
self.__clause_element__().clauses,
other.__composite_values__(),
)
]
)
# application of custom PropComparator subclasses
from sqlalchemy.orm import column_property, relationship, composite
from sqlalchemy import Column, String
class SomeMappedClass(Base):
some_column = column_property(
Column("some_column", String),
comparator_factory=MyColumnComparator,
)
some_relationship = relationship(
SomeOtherClass, comparator_factory=MyRelationshipComparator
)
some_composite = composite(
Column("a", String),
Column("b", String),
comparator_factory=MyCompositeComparator,
)
Note that for column-level operator redefinition, it's usually
simpler to define the operators at the Core level, using the
:attr:`.TypeEngine.comparator_factory` attribute. See
:ref:`types_operators` for more detail.
.. seealso::
:class:`.ColumnProperty.Comparator`
:class:`.Relationship.Comparator`
:class:`.Composite.Comparator`
:class:`.ColumnOperators`
:ref:`types_operators`
:attr:`.TypeEngine.comparator_factory`
Constructeur(s)
Liste des attributs statiques
adapter | <sqlalchemy.util.langhelpers._non_memoized_property object at 0x0000020DA0EDC890> |
info | <sqlalchemy.util.langhelpers._non_memoized_property object at 0x0000020DA0EDCAD0> |
prop | <member 'prop' of 'PropComparator' objects> |
property | <sqlalchemy.util.langhelpers._non_memoized_property object at 0x0000020DA0EDC410> |
timetuple | None |
Liste des opérateurs
Opérateurs hérités de la classe ColumnOperators
__add__, __contains__, __eq__, __floordiv__, __ge__, __getitem__, __gt__, __le__, __lshift__, __lt__, __mod__, __mul__, __ne__, __neg__, __radd__, __rfloordiv__, __rmod__, __rmul__, __rshift__, __rsub__, __rtruediv__, __sub__, __truediv__
Liste des opérateurs
Opérateurs hérités de la classe Operators
__and__, __invert__, __or__
Liste des méthodes
Toutes les méthodes
Méthodes d'instance
Méthodes statiques
Méthodes dépréciées
__class_getitem__ |
Parameterizes a generic class. [extrait de __class_getitem__.__doc__] |
__clause_element__(self) -> 'roles.ColumnsClauseRole' |
|
adapt_to_entity(self, adapt_to_entity: 'AliasedInsp[Any]') -> 'PropComparator[_T_co]' |
Return a copy of this PropComparator which will use the given [extrait de adapt_to_entity.__doc__] |
and_(self, *criteria: '_ColumnExpressionArgument[bool]') -> 'PropComparator[bool]' |
Add additional criteria to the ON clause that's represented by this [extrait de and_.__doc__] |
any(self, criterion: 'Optional[_ColumnExpressionArgument[bool]]' = None, **kwargs: 'Any') -> 'ColumnElement[bool]' |
Return a SQL expression representing true if this element [extrait de any.__doc__] |
any_op(a: 'Any', b: 'Any', **kwargs: 'Any') -> 'Any' |
|
has(self, criterion: 'Optional[_ColumnExpressionArgument[bool]]' = None, **kwargs: 'Any') -> 'ColumnElement[bool]' |
Return a SQL expression representing true if this element [extrait de has.__doc__] |
has_op(left: 'Any', other: 'Any', **kwargs: 'Any') -> 'Any' |
|
of_type(self, class_: '_EntityType[Any]') -> 'PropComparator[_T_co]' |
Redefine this object in terms of a polymorphic subclass, [extrait de of_type.__doc__] |
of_type_op(a: 'Any', class_: 'Any') -> 'Any' |
|
Méthodes héritées de la classe SQLORMOperations
__init_subclass__, __subclasshook__
Méthodes héritées de la classe ColumnOperators
all_, any_, asc, between, bitwise_and, bitwise_lshift, bitwise_not, bitwise_or, bitwise_rshift, bitwise_xor, collate, concat, contains, desc, distinct, endswith, icontains, iendswith, ilike, in_, is_, is_distinct_from, is_not, is_not_distinct_from, isnot, isnot_distinct_from, istartswith, like, match, not_ilike, not_in, not_like, notilike, notin_, notlike, nulls_first, nulls_last, nullsfirst, nullslast, regexp_match, regexp_replace, startswith
Méthodes héritées de la classe Operators
__sa_operate__, bool_op, op, operate, reverse_operate
Méthodes héritées de la classe object
__delattr__,
__dir__,
__format__,
__getattribute__,
__getstate__,
__hash__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__str__
Vous êtes un professionnel et vous avez besoin d'une formation ?
Programmation Python
Les compléments
Voir le programme détaillé
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 :