Check database when searching

Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
nathom 2021-07-11 11:31:29 -07:00
parent 2b68b96204
commit 4abe96825f
2 changed files with 25 additions and 3 deletions

View file

@ -73,7 +73,16 @@ class Database:
return bool(conn.execute(command, tuple(items.values())).fetchone()[0])
def __contains__(self, keys: dict) -> bool:
return self.contains(**keys)
if isinstance(keys, dict):
return self.contains(**keys)
if isinstance(keys, str) and len(self.structure) == 1:
only_key = tuple(self.structure.keys())[0]
query = {only_key: keys}
logger.debug("Searching for %s in database", query)
return self.contains(**query)
raise TypeError(keys)
def add(self, items: List[str]):
"""Add a row to the table.