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 ? Programmation Python
Les compléments
Voir le programme détaillé
Module « sqlalchemy.orm »

Classe « MapperEvents »

Informations générales

Héritage

builtins.object
    Generic
        _HasEventsDispatch
            Events
                MapperEvents

Définition

class MapperEvents(Events):

help(MapperEvents)

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 indicates 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 0x0000020DA14A81B0>

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

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

__subclasshook__

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

__init_subclass__

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 ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé