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.

Implement a `findFirst` API

See original GitHub issue

Problem

findOne is strict in that it requires a unique constraint (@unique, @id) to find a unique entry. That, however, doesn’t allow for more flexible kinds of queries which should also usually return a single result.

Suggested solution

findFirst, doing essentially a findMany + take: 1 under the hood.

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rootandleavescommented, Oct 8, 2020

Currently i am running my head to create query to retrieve first entry of any given table x in db. It would be convenient to have something like FindOldest or FindLastest with FindWithLastUpdatedOn (Based on @createdAt and @updatedAt timestamp)

1reaction
nickreynkecommented, Oct 2, 2020

Another use case to clarify why this is important.

Assume you have Workspaces where each User is either a simple participant or an owner. Per user input the user now wants to fetch a specific workspace by its id.

The findFirst comes in pretty handy because I can now find the first workspace where the id matches the given one AND the user is either a participant or the owner. This makes fetching the workspaces more secure since, in this case, it will only return those that are also attached to the current user.

Thank you for the implementation ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stream (Java Platform SE 8 ) - Oracle Help Center
We create a stream of Widget objects via Collection.stream() , filter it to produce a stream containing only the red widgets, and then...
Read more >
Implement a `findFirst` API · Issue #3676 · prisma ... - GitHub
Problem findOne is strict in that it requires a unique constraint (@unique, @id) to find a unique entry. That, however, doesn't allow for ......
Read more >
Java 8 Streams API - findAny, findFirst methods tutorial with ...
Introduction – This tutorial explains the Java 8 Stream API's findAny() and findFirst() methods with examples to show their usage.
Read more >
Stream findFirst() in Java with examples - GeeksforGeeks
Stream findFirst() returns an Optional (a container object which may or may not contain a non-null value) describing the first element of this ......
Read more >
Java 8 Stream findFirst() vs. findAny() | Baeldung
The article explains the difference between Java 8 Stream findFirst and findAny method, in sequential and parallel scenario.
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