liberapay/postgres.py

add a one_or_zero method

chadwhitacre opened this issue · 1 comments

Often you are fine with zero or one result but more than one would indicate a bug. Right now you can do:

try:
    rec = db.one(QUERY)
except TooFew:
    rec = None

if rec is None:
    pass
else:
    pass

But it might be nicer to be able to do:

rec = db.one_or_zero(QUERY)
if rec is None:
    pass
else:
    pass

This would also be good because the try/except form doesn't account for cases where rowcount is -1.