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

Function _slice_head

ormar/queryset/utils.py:187–209  ·  view source on GitHub ↗

Handles ``Model.objects[:N]`` — the first ``N`` rows of the result set. Negative ``stop`` would mean "everything except the last ``|N|`` rows", which needs a ``COUNT(*)`` to resolve, so it is rejected. Examples:: [:5] → SliceBounds(limit=5, offset=0, reverse=False)

(stop: int)

Source from the content-addressed store, hash-verified

185
186
187def _slice_head(stop: int) -> SliceBounds:
188 """
189 Handles ``Model.objects[:N]`` — the first ``N`` rows of the result set.
190 Negative ``stop`` would mean "everything except the last ``|N|`` rows",
191 which needs a ``COUNT(*)`` to resolve, so it is rejected.
192
193 Examples::
194
195 [:5] → SliceBounds(limit=5, offset=0, reverse=False)
196 [:0] → SliceBounds(limit=0, offset=0, reverse=False)
197 [:-2] → raises QueryDefinitionError
198
199 :param stop: upper bound from the slice
200 :type stop: int
201 :return: ``SliceBounds(limit=stop, offset=0, reverse=False)``
202 :rtype: SliceBounds
203 """
204 if stop < 0:
205 raise QueryDefinitionError(
206 "Negative slice stop without a start requires an explicit count; "
207 "use .count() with .offset()/.limit() instead."
208 )
209 return SliceBounds(limit=stop, offset=0, reverse=False)
210
211
212def _slice_tail(start: int) -> SliceBounds:

Callers 1

_slice_to_limit_offsetFunction · 0.85

Calls 2

SliceBoundsClass · 0.85

Tested by

no test coverage detected