Skip to content

Commit 5778fa8

Browse files
committed
Added documentation for iterability
1 parent 4b12fcd commit 5778fa8

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

docs/getting-started.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ Now you can get all elements stored in the database by running:
4040
>>> db.all()
4141
[{'count': 7, 'type': 'apple'}, {'count': 3, 'type': 'peach'}]
4242

43+
You can also iter over stored elements:
44+
45+
>>> for item in db:
46+
>>> print(item)
47+
{'count': 7, 'type': 'apple'}
48+
{'count': 3, 'type': 'peach'}
49+
4350
Of course you'll also want to search for specific elements. Let's try:
4451

4552
>>> Fruit = Query()
@@ -83,6 +90,8 @@ Before we dive deeper, let's recapitulate the basics:
8390
+-------------------------------+---------------------------------------------------------------+
8491
| ``db.all()`` | Get all elements |
8592
+-------------------------------+---------------------------------------------------------------+
93+
| ``iter(db)`` | Iter over all elements |
94+
+-------------------------------+---------------------------------------------------------------+
8695
| ``db.search(query)`` | Get a list of elements matching the query |
8796
+-------------------------------+---------------------------------------------------------------+
8897
| **Updating** |

docs/usage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ the ``TinyDB`` class. To create and use a table, use ``db.table(name)``.
339339
>>> table.insert({'value': True})
340340
>>> table.all()
341341
[{'value': True}]
342+
>>> for row in table:
343+
>>> print(row)
344+
{'value': True}
342345

343346
To remove a table from a database, use:
344347

0 commit comments

Comments
 (0)