MCPcopy
hub / github.com/tortoise/tortoise-orm / select_for_update

Method select_for_update

tortoise/queryset.py:589–625  ·  view source on GitHub ↗

Make QuerySet select for update. Returns a queryset that will lock rows until the end of the transaction, generating a SELECT ... FOR UPDATE SQL statement on supported databases. :param nowait: If `True`, raise an error if the lock cannot be obtained im

(
        self,
        nowait: bool = False,
        skip_locked: bool = False,
        of: tuple[str, ...] = (),
        no_key: bool = False,
    )

Source from the content-addressed store, hash-verified

587 return queryset
588
589 def select_for_update(
590 self,
591 nowait: bool = False,
592 skip_locked: bool = False,
593 of: tuple[str, ...] = (),
594 no_key: bool = False,
595 ) -> QuerySet[MODEL]:
596 """
597 Make QuerySet select for update.
598
599 Returns a queryset that will lock rows until the end of the transaction,
600 generating a SELECT ... FOR UPDATE SQL statement on supported databases.
601
602 :param nowait:
603 If `True`, raise an error if the lock cannot be obtained immediately.
604 :param skip_locked:
605 If `True`, skip rows that are already locked by other transactions instead of waiting.
606 :param of:
607 Specify the tables to lock when dealing with multiple related tables, e.g. when using `select_related`.
608 Provide a tuple of table names to indicate which tables' rows should be locked. By default, all fetched
609 rows are locked.
610 :param no_key:
611 If `True`, use the lower SELECT ... FOR NO KEY UPDATE lock strength on PostgreSQL to allow creating or
612 deleting rows in other tables that reference the locked rows via foreign keys. The parameter is ignored
613 on other backends.
614 """
615 if self.capabilities.support_for_update:
616 queryset = self._clone()
617 queryset._select_for_update = True
618 queryset._select_for_update_nowait = nowait
619 queryset._select_for_update_skip_locked = skip_locked
620 queryset._select_for_update_of = set(of)
621 queryset._select_for_update_no_key = (
622 no_key and self.capabilities.support_for_no_key_update
623 )
624 return queryset
625 return self
626
627 def annotate(self, **kwargs: Expression | Term) -> QuerySet[MODEL]:
628 """

Callers

nothing calls this directly

Calls 1

_cloneMethod · 0.95

Tested by

no test coverage detected