mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
.rows_where(..., order_by=) argument, closes #76
This commit is contained in:
parent
fc38868bd4
commit
125c625fbc
3 changed files with 42 additions and 2 deletions
|
|
@ -92,7 +92,7 @@ View objects are similar to Table objects, except that any attempts to insert or
|
|||
* ``count``
|
||||
* ``schema``
|
||||
* ``rows``
|
||||
* ``rows_where(where, where_args)``
|
||||
* ``rows_where(where, where_args, order_by)``
|
||||
* ``drop()``
|
||||
|
||||
.. _python_api_rows:
|
||||
|
|
@ -115,6 +115,22 @@ You can filter rows by a WHERE clause using ``.rows_where(where, where_args)``::
|
|||
... print(row)
|
||||
{'id': 1, 'age': 4, 'name': 'Cleo'}
|
||||
|
||||
To specify an order, use the ``order_my=`` argument::
|
||||
|
||||
>>> for row in db["dogs"].rows_where("age > 1", order_by="age"):
|
||||
... print(row)
|
||||
{'id': 2, 'age': 2, 'name': 'Pancakes'}
|
||||
{'id': 1, 'age': 4, 'name': 'Cleo'}
|
||||
|
||||
You can use ``order_by="age desc"`` for descending order.
|
||||
|
||||
You can order all records in the table by excluding the ``where`` argument::
|
||||
|
||||
>>> for row in db["dogs"].rows_where(order_by="age desc"):
|
||||
... print(row)
|
||||
{'id': 1, 'age': 4, 'name': 'Cleo'}
|
||||
{'id': 2, 'age': 2, 'name': 'Pancakes'}
|
||||
|
||||
.. _python_api_get:
|
||||
|
||||
Retrieving a specific record
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue