From aeb6b89f587ce6ca4e2872d4eb43461d8a7f2782 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 3 Jun 2022 19:42:20 -0700 Subject: [PATCH] Add parameter fallback to select_one_value. --- voussoirkit/worms.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 3f54cb5..aa152e5 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -426,17 +426,18 @@ class Database(metaclass=abc.ABCMeta): cur = self.execute(query, bindings) return cur.fetchone() - def select_one_value(self, query, bindings=None): + def select_one_value(self, query, bindings=None, fallback=None): ''' - Select a single column out of a single row, or None if no rows match - your query. + Select a single column out of a single row, or fallback if no rows match + your query. The fallback can help you distinguish between rows that + don't exist and a null value. ''' cur = self.execute(query, bindings) row = cur.fetchone() if row: return row[0] else: - return None + return fallback def update(self, table, pairs, where_key) -> sqlite3.Cursor: if isinstance(table, type) and issubclass(table, Object):