New .rows_where(select=) argument

This commit is contained in:
Simon Willison 2020-09-22 16:10:14 -07:00
commit 71782311ce
3 changed files with 11 additions and 4 deletions

View file

@ -145,7 +145,7 @@ View objects are similar to Table objects, except that any attempts to insert or
* ``count``
* ``schema``
* ``rows``
* ``rows_where(where, where_args, order_by)``
* ``rows_where(where, where_args, order_by, select)``
* ``drop()``
.. _python_api_rows:
@ -168,6 +168,13 @@ You can filter rows by a WHERE clause using ``.rows_where(where, where_args)``::
... print(row)
{'id': 1, 'age': 4, 'name': 'Cleo'}
To return custom columns (instead of using ``select *``) pass ``select=``::
>>> db = sqlite_utils.Database("dogs.db")
>>> for row in db["dogs"].rows_where(select='name, age'):
... print(row)
{'name': 'Cleo', 'age': 4}
To specify an order, use the ``order_by=`` argument::
>>> for row in db["dogs"].rows_where("age > 1", order_by="age"):