Replies: 1 comment
-
Hey @Danelfcf, I'm not sure what you mean to do with the from tinydb import TinyDB, Query
db = TinyDB('test.json')
db.truncate()
db.insert({'name': 'John', 'age': 22, 'job': 'student'})
db.insert({'name': 'John1', 'age': 23, 'job': 'student'})
db.insert({'name': 'John2', 'age': 24, 'job': 'student'})
db.insert({'name': 'John3', 'age': 25, 'job': 'student'})
def find(fields, x):
'''
Example usage: print(db.find(['type'], ['apple']))
:param fields: list(str) database 'columns' to look at
:param x: list(str) values in cols to look for
:return: list[dic{}]
'''
query = Query()[fields.pop(0)].one_of(x)
for field in fields:
query = query | Query()[field].one_of(x)
return db.search(query)
print(find(['age', 'name'], [22, 23, 'John3'])) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi I am trying to use tinydb for a parametic search, however I am having a hard time with the Query. what I want to do is the following:
I have a database created like db.insert({'name': 'John', 'age': 22, 'job'='student'}) and I want to setup a search where I only look for the fields name and age. while I can do this by hand I want to be able to pass a list of feilds and a list of values like the following:
while I know how to handle checking for the values using one_of, I cannot find the equivalent command for the 'field'.
Beta Was this translation helpful? Give feedback.
All reactions