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.

Allow findUnique to accept more than one search parameter

See original GitHub issue

Problem

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:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ArthurThorntoncommented, May 6, 2021

@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 if result.active isn’t true.

See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference/#unique-1 for docs on compound uniqueness.

0reactions
IdanYekutielcommented, May 1, 2021

This is something I have been trying to figure out too.

Read more comments on GitHub >

github_iconTop 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 >

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