Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a one_or_zero method #19

Closed
chadwhitacre opened this issue Aug 8, 2013 · 1 comment
Closed

add a one_or_zero method #19

chadwhitacre opened this issue Aug 8, 2013 · 1 comment

Comments

@chadwhitacre
Copy link
Collaborator

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
@chadwhitacre
Copy link
Collaborator Author

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

chadwhitacre added a commit that referenced this issue Aug 10, 2013
The one method is too complex for this common case, it turns out. :-/
chadwhitacre added a commit that referenced this issue Aug 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant