Skip to content

runSelectReturningOne should not return Nothing for more than one row #367

Open
@moll

Description

@moll

As asked on IRC, creating an issue for discussion.

runSelectReturningOne returns Nothing when more than one row matches the query. #268 states this is by design.

I claim that returning Nothing when more than one row is returned is a risky choice. It's correct to state the row ordering may not be defined and non-determinism may result, but returning Nothing signifies there are no rows that match the given constraints. That's likely to lead code to attempt to create a row and then fail either with a database constraint failure, or to further exacerbate the duplicate row problem. Secondly, a lot of other ORMs and database layers do not behave like this. Be it an OO .first or a functional getFirst, they often tack on a LIMIT 1 and get on with it. runSelectReturningOne, while not modifying the query to optimize with a LIMIT 1, shouldn't at least behave in an unexpecting manner. I, for one, leaned towards runSelectReturningOne to not have to do listToMaybe, and didn't think twice whether there are or aren't duplicate rows.

Cheers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions