Add parameter fallback to select_one_value.
This commit is contained in:
parent
2c8081505a
commit
aeb6b89f58
1 changed files with 5 additions and 4 deletions
|
@ -426,17 +426,18 @@ class Database(metaclass=abc.ABCMeta):
|
||||||
cur = self.execute(query, bindings)
|
cur = self.execute(query, bindings)
|
||||||
return cur.fetchone()
|
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
|
Select a single column out of a single row, or fallback if no rows match
|
||||||
your query.
|
your query. The fallback can help you distinguish between rows that
|
||||||
|
don't exist and a null value.
|
||||||
'''
|
'''
|
||||||
cur = self.execute(query, bindings)
|
cur = self.execute(query, bindings)
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
if row:
|
if row:
|
||||||
return row[0]
|
return row[0]
|
||||||
else:
|
else:
|
||||||
return None
|
return fallback
|
||||||
|
|
||||||
def update(self, table, pairs, where_key) -> sqlite3.Cursor:
|
def update(self, table, pairs, where_key) -> sqlite3.Cursor:
|
||||||
if isinstance(table, type) and issubclass(table, Object):
|
if isinstance(table, type) and issubclass(table, Object):
|
||||||
|
|
Loading…
Reference in a new issue