diff options
author | jfinkels <jfinkels@users.noreply.github.com> | 2016-03-13 15:40:11 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-03-13 16:39:36 -0400 |
commit | d7178007fca2f91ba933302345ea2b92cb6ebb27 (patch) | |
tree | cf535a6d73a1bc4aec7c7afe889fe3482f85bc29 | |
parent | 71f8a6027f4defe5911020c5cc9581a4fbfaafc0 (diff) | |
download | sqlalchemy-d7178007fca2f91ba933302345ea2b92cb6ebb27.tar.gz |
Adds documentation to Query.slice().
(cherry picked from commit 6e5e64e27ef2c6a86c9aebdcefdf2cd726f1476a)
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 335832d1d..b5151c109 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2463,9 +2463,35 @@ class Query(object): @_generative(_no_statement_condition) def slice(self, start, stop): - """apply LIMIT/OFFSET to the ``Query`` based on a " - "range and return the newly resulting ``Query``.""" + """Computes the "slice" of the :class:`.Query` represented by + the given indices and returns the resulting :class:`.Query`. + The start and stop indices behave like the argument to Python's + built-in :func:`range` function. This method provides an + alternative to using ``LIMIT``/``OFFSET`` to get a slice of the + query. + + For example, :: + + session.query(User).order_by(User.id).slice(1, 3) + + renders as + + .. sourcecode:: sql + + SELECT users.id AS users_id, + users.name AS users_name + FROM users ORDER BY users.id + LIMIT ? OFFSET ? + (2, 1) + + .. seealso:: + + :meth:`.Query.limit` + + :meth:`.Query.offset` + + """ if start is not None and stop is not None: self._offset = (self._offset or 0) + start self._limit = stop - start @@ -2480,7 +2506,6 @@ class Query(object): @_generative(_no_statement_condition) def limit(self, limit): """Apply a ``LIMIT`` to the query and return the newly resulting - ``Query``. """ |