Add select_one_value.

This commit is contained in:
voussoir 2022-03-14 15:34:41 -07:00
parent 38f9d8046c
commit 512f1591ef
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -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