MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / slice

Method slice

lib/sqlalchemy/orm/query.py:2606–2646  ·  view source on GitHub ↗

Computes the "slice" of the :class:`_query.Query` represented by the given indices and returns the resulting :class:`_query.Query`. The start and stop indices behave like the argument to Python's built-in :func:`range` function. This method provides an alternative to

(
        self,
        start: int,
        stop: int,
    )

Source from the content-addressed store, hash-verified

2604 @_generative
2605 @_assertions(_no_statement_condition)
2606 def slice(
2607 self,
2608 start: int,
2609 stop: int,
2610 ) -> Self:
2611 """Computes the "slice" of the :class:`_query.Query` represented by
2612 the given indices and returns the resulting :class:`_query.Query`.
2613
2614 The start and stop indices behave like the argument to Python's
2615 built-in :func:`range` function. This method provides an
2616 alternative to using ``LIMIT``/``OFFSET`` to get a slice of the
2617 query.
2618
2619 For example, ::
2620
2621 session.query(User).order_by(User.id).slice(1, 3)
2622
2623 renders as
2624
2625 .. sourcecode:: sql
2626
2627 SELECT users.id AS users_id,
2628 users.name AS users_name
2629 FROM users ORDER BY users.id
2630 LIMIT ? OFFSET ?
2631 (2, 1)
2632
2633 .. seealso::
2634
2635 :meth:`_query.Query.limit`
2636
2637 :meth:`_query.Query.offset`
2638
2639 :meth:`_sql.Select.slice` - v2 equivalent method.
2640
2641 """
2642
2643 self._limit_clause, self._offset_clause = sql_util._make_slice(
2644 self._limit_clause, self._offset_clause, start, stop
2645 )
2646 return self
2647
2648 @_generative
2649 @_assertions(_no_statement_condition)

Callers 6

firstMethod · 0.45
_getitemFunction · 0.45
CoreFixturesClass · 0.45
test_filterMethod · 0.45
test_valuesMethod · 0.45

Calls

no outgoing calls

Tested by 3

test_filterMethod · 0.36
test_valuesMethod · 0.36