From 512f1591efa7949aad6806bba5abb193efc4b655 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 14 Mar 2022 15:34:41 -0700 Subject: [PATCH] Add select_one_value. --- voussoirkit/worms.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 2aed612..908d892 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -383,9 +383,24 @@ class Database(metaclass=abc.ABCMeta): yield row[0] def select_one(self, query, bindings=None): + ''' + Select a single row, or None if no rows match your query. + ''' cur = self.execute(query, bindings) return cur.fetchone() + def select_one_value(self, query, bindings=None): + ''' + Select a single column out of a single row, or None if no rows match + your query. + ''' + cur = self.execute(query, bindings) + row = cur.fetchone() + if row: + return row[0] + else: + return None + def update(self, table, pairs, where_key) -> None: if isinstance(table, type) and issubclass(table, Object): table = table.table