Allow findUnique to accept more than one search parameter
See original GitHub issueProblem
Currently findUnique function only accepts one parameter when where is called, I believe it could be better if this function accepted more than one parameter to search, the Prisma docs recommends using findFirst but this function calls findMany as the same docs describe.
Suggested solution
Allow findUnique function to accept more than one parameter at Where.
Additional context
This:
const result = await prisma.user.findUnique({
where: {
email: 'alice@prisma.io',
},
})
Could turn into this:
const result = await prisma.user.findUnique({
where: {
email: 'alice@prisma.io',
active: true
},
})
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
prisma findUnique where takes only one unique argument
I am not entirely certain, but prisma returns a JS object... So perhaps a query like this should work: const query = await...
Read more >Prisma Client API (Reference)
findUniqueOrThrow retrieves a single data record in the same way as findUnique . However, if the query does not find a record, it...
Read more >Using Lookup and multivalued fields in queries
In Access, you can create a multivalued field that holds multiple values (up to 100) ... The display value of a Lookup field...
Read more >Find the element that appears once in an array where every ...
Given an array of integers. All numbers occur twice except one number which occurs once. Find the number in O(n) time & constant...
Read more >Python Unique List – How to Get all the Unique Values in a ...
There are other ways to find unique values in a Python list. But you'll probably find yourself reaching for one of the approaches...
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
@edilson and @IdanYekutiel - for this case you can define a compound uniqueness constraint on your model so you can query against multiple fields as a single unique entity; this is only really appropriate/applicable if your database has this limitation as well. If your database already has a unique on
email
then you might as well get the user based on this and just check ifresult.active
isn’ttrue
.See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference/#unique-1 for docs on compound uniqueness.
This is something I have been trying to figure out too.