question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getOneOrFail() -> getFirstOneOrFail() & add getExactlyOneOrFail()

See original GitHub issue

Feature Description

Rename getOneOrFail and / or add getExactlyOneOrFail method.

The Problem

I argue that the naming getOneOrFail is ambiguous. Using getOneOrFail with a query that returns more than one row could lead to hard to find bugs.

The Solution

BREAKING CHANGE: rename getOneOrFail -> getFirstOneOrFail. FEATURE: add method getExactlyOneOrFail

Considered Alternatives

I know that this is a minor change and maybe not priorities but I think that clarity should always be increased if possible.

Relevant Database Driver(s)

DB Type Relevant
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql yes
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite yes
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

Yes

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
pleerockcommented, Feb 17, 2022

Using getOneOrFail with a query that returns more than one row could lead to hard to find bugs.

findOneOrFail appends LIMIT 1 that prevents you from getting multiple rows from the db.

1reaction
pleerockcommented, Feb 18, 2022

Maybe this feature is useful in some scenarios, but I don’t think we need to extend exist find API. Consider creating your repository like @Ginden did and use this method in your project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select using Query Builder - typeorm - GitBook
getOne(). It builds the following SQL query: SELECT. user.id as userId, ... getOneOrFail will get a single result from the database, but if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found