MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / yield_per

Method yield_per

lib/sqlalchemy/orm/query.py:1035–1058  ·  view source on GitHub ↗

r"""Yield only ``count`` rows at a time. The purpose of this method is when fetching very large result sets (> 10K rows), to batch results in sub-collections and yield them out partially, so that the Python interpreter doesn't need to declare very large areas of memo

(self, count: int)

Source from the content-addressed store, hash-verified

1033
1034 @_generative
1035 def yield_per(self, count: int) -> Self:
1036 r"""Yield only ``count`` rows at a time.
1037
1038 The purpose of this method is when fetching very large result sets
1039 (> 10K rows), to batch results in sub-collections and yield them
1040 out partially, so that the Python interpreter doesn't need to declare
1041 very large areas of memory which is both time consuming and leads
1042 to excessive memory use. The performance from fetching hundreds of
1043 thousands of rows can often double when a suitable yield-per setting
1044 (e.g. approximately 1000) is used, even with DBAPIs that buffer
1045 rows (which are most).
1046
1047 As of SQLAlchemy 1.4, the :meth:`_orm.Query.yield_per` method is
1048 equivalent to using the ``yield_per`` execution option at the ORM
1049 level. See the section :ref:`orm_queryguide_yield_per` for further
1050 background on this option.
1051
1052 .. seealso::
1053
1054 :ref:`orm_queryguide_yield_per`
1055
1056 """
1057 self.load_options += {"_yield_per": count}
1058 return self
1059
1060 @util.became_legacy_20(
1061 ":meth:`_orm.Query.get`",

Calls

no outgoing calls