MCPcopy
hub / github.com/ormar-orm/ormar / delete

Method delete

ormar/queryset/queryset.py:911–939  ·  view source on GitHub ↗

Deletes from the model table after applying the filters from kwargs. You have to either pass a filter to narrow down a query or explicitly pass each=True flag to affect whole table. :param each: flag if whole table should be affected if no filter is passed

(self, *args: Any, each: bool = False, **kwargs: Any)

Source from the content-addressed store, hash-verified

909 return await executor.execute(expr)
910
911 async def delete(self, *args: Any, each: bool = False, **kwargs: Any) -> int:
912 """
913 Deletes from the model table after applying the filters from kwargs.
914
915 You have to either pass a filter to narrow down a query or explicitly pass
916 each=True flag to affect whole table.
917
918 :param each: flag if whole table should be affected if no filter is passed
919 :type each: bool
920 :param kwargs: fields names and proper value types
921 :type kwargs: Any
922 :return: number of deleted rows
923 :rtype:int
924 """
925 if kwargs or args:
926 return await self.filter(*args, **kwargs).delete()
927 if not each and not (self.filter_clauses or self.exclude_clauses):
928 raise QueryDefinitionError(
929 "You cannot delete without filtering the queryset first. "
930 "If you want to delete all rows use delete(each=True)"
931 )
932 expr = FilterQuery(filter_clauses=self.filter_clauses).apply(
933 self.table.delete() # type: ignore
934 )
935 expr = FilterQuery(filter_clauses=self.exclude_clauses, exclude=True).apply(
936 expr
937 )
938 async with self.model_config.database.get_query_executor() as executor:
939 return await executor.execute(expr)
940
941 def paginate(self, page: int, page_size: int = 20) -> "QuerySet[T]":
942 """

Callers 1

clearMethod · 0.95

Calls 6

filterMethod · 0.95
FilterQueryClass · 0.90
get_query_executorMethod · 0.80
executeMethod · 0.80
applyMethod · 0.45

Tested by

no test coverage detected