Implement a `findFirst` API
See original GitHub issueProblem
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:
- Created 3 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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)
Another use case to clarify why this is important.
Assume you have
Workspace
s where eachUser
is either a simple participant or an owner. Per user input the user now wants to fetch a specific workspace by itsid
.The
findFirst
comes in pretty handy because I can now find the first workspace where theid
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 ❤️