- Notifications
You must be signed in to change notification settings - Fork590
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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: deffind(self,field,x):''' Example usage: print(db.find(['type'], ['apple'])) :param field: list(str) database 'columns' to look at :param x: list(str) values in cols to look for :return: list[dic{}] '''returnself.db.search(self.q[tuple(field)].one_of(x))# so in my case I want to input something like:print(class.find(["Jill","John"], [22,23,85])) while I know how to handle checking for the values using one_of, I cannot find the equivalent command for the 'field'. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
Hey@Danelfcf, I'm not sure what you mean to do with the fromtinydbimportTinyDB,Querydb=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'})deffind(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)forfieldinfields:query=query|Query()[field].one_of(x)returndb.search(query)print(find(['age','name'], [22,23,'John3'])) |
BetaWas this translation helpful?Give feedback.