The TinyDB forum has found a new home at GitHub discussions. The content here remains as a read-only archive.
db.all() [{'fruit name': 'apple', 'count': 7}, {'fruit name': 'pear', 'count': 8}]
how to search fruit name == apple ?
db.search(query['fruit name'] == 'apple')
Hey liuguiyu,
that's correct. You also can use the where helper:
where
from tinydb import where db.search(where('fruit name') == 'apple')
Cheers!
msiemens
where helper ... it's cool, just i didnt see this in the online doc ...
liuguiyu just i didnt see this in the online doc ...
I admit it's a little hidden, but in my defence there's a paragraph in http://tinydb.readthedocs.io/en/latest/usage.html#queries (at the bottom of the section) ?
The second, traditional way of constructing queries is as follows: >>> from tinydb import where >>> db.search(where('field') == 'value') Using where('field') is a shorthand for the following code: >>> db.search(Query()['field'] == 'value')
The second, traditional way of constructing queries is as follows:
>>> from tinydb import where >>> db.search(where('field') == 'value')
Using where('field') is a shorthand for the following code:
>>> db.search(Query()['field'] == 'value')