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 fondamentaux
Voir le programme détaillé
Classe « Query »

Méthode sqlalchemy.orm.Query.with_for_update

Signature de la méthode with_for_update

def with_for_update(self, *, nowait: 'bool' = False, read: 'bool' = False, of: 'Optional[_ForUpdateOfArgument]' = None, skip_locked: 'bool' = False, key_share: 'bool' = False) -> 'Self' 

Description

help(Query.with_for_update)

return a new :class:`_query.Query`
with the specified options for the
``FOR UPDATE`` clause.

The behavior of this method is identical to that of
:meth:`_expression.GenerativeSelect.with_for_update`.
When called with no arguments,
the resulting ``SELECT`` statement will have a ``FOR UPDATE`` clause
appended.  When additional arguments are specified, backend-specific
options such as ``FOR UPDATE NOWAIT`` or ``LOCK IN SHARE MODE``
can take effect.

E.g.::

    q = (
        sess.query(User)
        .populate_existing()
        .with_for_update(nowait=True, of=User)
    )

The above query on a PostgreSQL backend will render like:

.. sourcecode:: sql

    SELECT users.id AS users_id FROM users FOR UPDATE OF users NOWAIT

.. warning::

    Using ``with_for_update`` in the context of eager loading
    relationships is not officially supported or recommended by
    SQLAlchemy and may not work with certain queries on various
    database backends.  When ``with_for_update`` is successfully used
    with a query that involves :func:`_orm.joinedload`, SQLAlchemy will
    attempt to emit SQL that locks all involved tables.

.. note::  It is generally a good idea to combine the use of the
   :meth:`_orm.Query.populate_existing` method when using the
   :meth:`_orm.Query.with_for_update` method.   The purpose of
   :meth:`_orm.Query.populate_existing` is to force all the data read
   from the SELECT to be populated into the ORM objects returned,
   even if these objects are already in the :term:`identity map`.

.. seealso::

    :meth:`_expression.GenerativeSelect.with_for_update`
    - Core level method with
    full argument and behavioral description.

    :meth:`_orm.Query.populate_existing` - overwrites attributes of
    objects already loaded in the identity map.



Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé