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 « MapperEvents »

Informations générales

Héritage

builtins.object
    Events
        MapperEvents

Définition

class MapperEvents(Events):

Description [extrait de MapperEvents.__doc__]

Define events specific to mappings.

    e.g.::

        from sqlalchemy import event

        def my_before_insert_listener(mapper, connection, target):
            # execute a stored procedure upon INSERT,
            # apply the value to the row to be inserted
            target.calculated_value = connection.execute(
                text("select my_special_function(%d)" % target.special_number)
            ).scalar()

        # associate the listener function with SomeClass,
        # to execute during the "before_insert" hook
        event.listen(
            SomeClass, 'before_insert', my_before_insert_listener)

    Available targets include:

    * mapped classes
    * unmapped superclasses of mapped or to-be-mapped classes
      (using the ``propagate=True`` flag)
    * :class:`_orm.Mapper` objects
    * the :class:`_orm.Mapper` class itself and the :func:`.mapper`
      function indicate listening for all mappers.

    Mapper events provide hooks into critical sections of the
    mapper, including those related to object instrumentation,
    object loading, and object persistence. In particular, the
    persistence methods :meth:`~.MapperEvents.before_insert`,
    and :meth:`~.MapperEvents.before_update` are popular
    places to augment the state being persisted - however, these
    methods operate with several significant restrictions. The
    user is encouraged to evaluate the
    :meth:`.SessionEvents.before_flush` and
    :meth:`.SessionEvents.after_flush` methods as more
    flexible and user-friendly hooks in which to apply
    additional database state during a flush.

    When using :class:`.MapperEvents`, several modifiers are
    available to the :func:`.event.listen` function.

    :param propagate=False: When True, the event listener should
       be applied to all inheriting mappers and/or the mappers of
       inheriting classes, as well as any
       mapper which is the target of this listener.
    :param raw=False: When True, the "target" argument passed
       to applicable event listener functions will be the
       instance's :class:`.InstanceState` management
       object, rather than the mapped instance itself.
    :param retval=False: when True, the user-defined event function
       must have a return value, the purpose of which is either to
       control subsequent event propagation, or to otherwise alter
       the operation in progress by the mapper.   Possible return
       values are:

       * ``sqlalchemy.orm.interfaces.EXT_CONTINUE`` - continue event
         processing normally.
       * ``sqlalchemy.orm.interfaces.EXT_STOP`` - cancel all subsequent
         event handlers in the chain.
       * other values - the return value specified by specific listeners.

    

Constructeur(s)

Signature du constructeur Description
__init__(self, /, *args, **kwargs) Initialize self. See help(type(self)) for accurate signature. [extrait de __init__.__doc__]

Liste des attributs statiques

Nom de l'attribut Valeur
dispatch<sqlalchemy.event.base.MapperEventsDispatch object at 0x7f40cb852020>

Liste des opérateurs

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

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

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
after_configured(self) Called after a series of mappers have been configured. [extrait de after_configured.__doc__]
after_delete(self, mapper, connection, target) Receive an object instance after a DELETE statement [extrait de after_delete.__doc__]
after_insert(self, mapper, connection, target) Receive an object instance after an INSERT statement [extrait de after_insert.__doc__]
after_update(self, mapper, connection, target) Receive an object instance after an UPDATE statement [extrait de after_update.__doc__]
before_configured(self) Called before a series of mappers have been configured. [extrait de before_configured.__doc__]
before_delete(self, mapper, connection, target) Receive an object instance before a DELETE statement [extrait de before_delete.__doc__]
before_insert(self, mapper, connection, target) Receive an object instance before an INSERT statement [extrait de before_insert.__doc__]
before_mapper_configured(self, mapper, class_) Called right before a specific mapper is to be configured. [extrait de before_mapper_configured.__doc__]
before_update(self, mapper, connection, target) Receive an object instance before an UPDATE statement [extrait de before_update.__doc__]
instrument_class(self, mapper, class_) Receive a class when the mapper is first constructed, [extrait de instrument_class.__doc__]
mapper_configured(self, mapper, class_) Called when a specific mapper has completed its own configuration [extrait de mapper_configured.__doc__]

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

__init_subclass__, __subclasshook__

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

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