Add select_one_value.
This commit is contained in:
parent
38f9d8046c
commit
512f1591ef
1 changed files with 15 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue