Skip to content

How to chain queries? #422

Answered by msiemens
yashrathi-git asked this question in Q&A
Discussion options

You must be logged in to vote

The way TinyDB Queries work is that they are callables which return True if they match a document. This means that you can take a query and apply it to a list of objects like this:

docs = db.search(query1)
docs = filter(query2, docs)
# or:
docs = [doc for doc in docs if query2(doc)]

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yashrathi-git
Comment options

Answer selected by yashrathi-git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants