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 :

Module « sqlalchemy.orm »

Classe « PropComparator »

Informations générales

Héritage

builtins.object
    Operators
        ColumnOperators
            PropComparator

Définition

class PropComparator(ColumnOperators):

Description [extrait de PropComparator.__doc__]

Defines SQL operators for :class:`.MapperProperty` objects.

    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:`.RelationshipProperty`, and :class:`.CompositeProperty`.

    .. note:: With the advent of Hybrid properties introduced in SQLAlchemy
       0.7, as well as Core-level operator redefinition in
       SQLAlchemy 0.8, the use case for user-defined :class:`.PropComparator`
       instances is extremely rare.  See :ref:`hybrids_toplevel` as well
       as :ref:`types_operators`.

    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,\
                                CompositeProperty,\
                                RelationshipProperty

        class MyColumnComparator(ColumnProperty.Comparator):
            def __eq__(self, other):
                return self.__clause_element__() == other

        class MyRelationshipComparator(RelationshipProperty.Comparator):
            def any(self, expression):
                "define the 'any' operation"
                # ...

        class MyCompositeComparator(CompositeProperty.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:`.RelationshipProperty.Comparator`

        :class:`.CompositeProperty.Comparator`

        :class:`.ColumnOperators`

        :ref:`types_operators`

        :attr:`.TypeEngine.comparator_factory`

    

Constructeur(s)

Signature du constructeur Description
__init__(self, prop, parentmapper, adapt_to_entity=None)

Liste des attributs statiques

Nom de l'attribut Valeur
prop<member 'prop' of 'PropComparator' objects>
property<member 'property' of 'PropComparator' objects>
timetupleNone

Liste des propriétés

Nom de la propriétéDescription
adapterProduce a callable that adapts column expressions [extrait de __doc__]
info

Liste des opérateurs

Opérateurs hérités de la classe ColumnOperators

__add__, __contains__, __eq__, __ge__, __getitem__, __gt__, __le__, __lshift__, __lt__, __mod__, __mul__, __ne__, __neg__, __radd__, __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
Signature de la méthodeDescription
__clause_element__(self)
adapt_to_entity(self, adapt_to_entity) Return a copy of this PropComparator which will use the given [extrait de adapt_to_entity.__doc__]
and_(self, *criteria) Add additional criteria to the ON clause that's represented by this [extrait de and_.__doc__]
any(self, criterion=None, **kwargs) Return true if this collection contains any member that meets the [extrait de any.__doc__]
any_op(a, b, **kwargs)
has(self, criterion=None, **kwargs) Return true if this element references a member which meets the [extrait de has.__doc__]
has_op(a, b, **kwargs)
of_type(self, class_) Redefine this object in terms of a polymorphic subclass, [extrait de of_type.__doc__]
of_type_op(a, class_)

Méthodes héritées de la classe ColumnOperators

__div__, __init_subclass__, __rdiv__, __subclasshook__, all_, any_, asc, between, collate, concat, contains, desc, distinct, endswith, ilike, in_, is_, is_distinct_from, is_not, is_not_distinct_from, isnot, isnot_distinct_from, 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

bool_op, op, operate, reverse_operate

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__