mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-27 20:34:12 +02:00
Improved .rows_where() documentation, added test for :named parameters
This commit is contained in:
parent
670f92285f
commit
2dad4f583c
2 changed files with 8 additions and 1 deletions
|
|
@ -202,7 +202,13 @@ You can filter rows by a WHERE clause using ``.rows_where(where, where_args)``::
|
||||||
... print(row)
|
... print(row)
|
||||||
{'id': 1, 'age': 4, 'name': 'Cleo'}
|
{'id': 1, 'age': 4, 'name': 'Cleo'}
|
||||||
|
|
||||||
To return custom columns (instead of using ``select *``) pass ``select=``::
|
The first argument is a fragment of SQL. The second, optional argument is values to be passed to that fragment - you can use ``?`` placeholders and pass an array, or you can use ``:named`` parameters and pass a dictionary, like this::
|
||||||
|
|
||||||
|
>>> for row in db["dogs"].rows_where("age > :age", {"age": 3}):
|
||||||
|
... print(row)
|
||||||
|
{'id': 1, 'age': 4, 'name': 'Cleo'}
|
||||||
|
|
||||||
|
To return custom columns (instead of the default that uses ``select *``) pass ``select="column1, column2"``::
|
||||||
|
|
||||||
>>> db = sqlite_utils.Database("dogs.db")
|
>>> db = sqlite_utils.Database("dogs.db")
|
||||||
>>> for row in db["dogs"].rows_where(select='name, age'):
|
>>> for row in db["dogs"].rows_where(select='name, age'):
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ def test_rows(existing_db):
|
||||||
[
|
[
|
||||||
("name = ?", ["Pancakes"], {2}),
|
("name = ?", ["Pancakes"], {2}),
|
||||||
("age > ?", [3], {1}),
|
("age > ?", [3], {1}),
|
||||||
|
("age > :age", {"age": 3}, {1}),
|
||||||
("name is not null", [], {1, 2}),
|
("name is not null", [], {1, 2}),
|
||||||
("is_good = ?", [True], {1, 2}),
|
("is_good = ?", [True], {1, 2}),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue