Am 22.04.2019 um 21:15 schrieb Justin Pryzby:
> I suggest that single() should return None for n==0,
> and MultipleResultsFoun> for n>1.

Actually I already added a one() method that is sloppy and returns None. The single() method is the opposite and considered to be very strict, when you really expect one and only one value from the database.

In SQLALchemy, one() is called first() and single() is called one(), which is a bit unfortunate, but in SQLAlchemy the latter also throws when there is no value.

I chose the name one() instead of first() to be more in line with pgdb and because it can be called multiple times to get the following rows, so that the name first() was not appropriate.

single() also corresponds in name and semantics to the Single() method in LINQ which also throws if not exactly one row.

I really don't want to introduce a third method that throw only if you have more than 1 result, but not for 0 results.

> If you wanted to be really extreme you could have THREE subclasses...
> |class NotOnlyOne(DataError):pass
> |class MoreThanOne(NotOnlyOne):pass
> |class LessThanOne(NotOnlyOne):pass

Yes, a bit extreme, but necessary to avoid the need for catching 2 different errors. Maybe the top level should just be InvalidResult instead of NotSingleResult or NotOnlyOne?

-- Christoph
_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
https://mail.vex.net/mailman/listinfo/pygresql

Reply via email to