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 query_one method that ensures a single result #358

Open
tgross35 opened this issue Sep 10, 2023 · 1 comment
Open

Add a query_one method that ensures a single result #358

tgross35 opened this issue Sep 10, 2023 · 1 comment

Comments

@tgross35
Copy link

tgross35 commented Sep 10, 2023

This kind of method is helpful for when you expect a single item, and any more would indicate an error. The signature would be approximately:

fn query_one<T, Q>(&mut self, query: Q) -> Result<T>
where
    Q: AsRef<str>,
    T: FromRow,

Any result count other than one returns an error.

@blackbeam
Copy link
Owner

Hi. Whether some query returns one or multiple rows depends mostly on the query itself that, in turn, depends on the application logic. I believe this shouldn't be a driver problem. From the driver perspective this adds a new error variant ManyOrNoRowsReturnedWhileExactlyOneRowIsExpected that seems odd for a database driver to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants