Add select_one_value.

master
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
1 changed files with 15 additions and 0 deletions

View File

@ -383,9 +383,24 @@ class Database(metaclass=abc.ABCMeta):
yield row[0] yield row[0]
def select_one(self, query, bindings=None): def select_one(self, query, bindings=None):
'''
Select a single row, or None if no rows match your query.
'''
cur = self.execute(query, bindings) cur = self.execute(query, bindings)
return cur.fetchone() 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: def update(self, table, pairs, where_key) -> None:
if isinstance(table, type) and issubclass(table, Object): if isinstance(table, type) and issubclass(table, Object):
table = table.table table = table.table