Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find entry in dataset using dictionary

I use dataset in python to create and query databases. It takes dictionaries to create an entry:

entry1={}; entry[id]=1;entry[name]='a'
DBd['data'].insert(entry1)

I would like to make sure that I do not enter the entry if it already exists. However, the find method doesn't take dictionaries, but would work as follows:

DB['data'].find(id=1,name='a')

is there some way that I could do something like

DB['data'].find(entry1)

i.e. I would need to convert the dictionary into a valid filter.

like image 880
user1638145 Avatar asked Feb 28 '26 00:02

user1638145


1 Answers

You can turn a dictionary into parameters using **kwargs parameters like this:

DB['data'].find(**entry1)
like image 80
Brent Washburne Avatar answered Mar 02 '26 14:03

Brent Washburne