if you are looking for a unique value that would bring you a single result you can use findFirst as well. which would give you Object instead of Array. findMany returns an Array even though you are looking for a unique value.

const users = await prisma.user.findFirst({
  where: {OR: [{username},{email}]}
});
Answer from Bora ALAP on Stack Overflow
🌐
Prisma
prisma.io › home › crud › crud › crud › crud
CRUD (Reference) | Prisma Documentation
// By unique field const user = await prisma.user.findUnique({ where: { email: "elsa@prisma.io" }, }); // By ID const user = await prisma.user.findUnique({ where: { id: 99 }, });
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
const result = await prisma.user.findUnique({ where: { email: "alice@prisma.io", }, }); Expand for example User model with a @@unique block
Discussions

prisma findUnique where takes only one unique argument - Stack Overflow
Nikolas from the Prisma team here. I don't think the select makes a difference but this is key: "I am not sure exactly why you would select user + email as both unique, as I would assume that one is tied to the other anyhow." Since both id and email are already unique properties, it doesn't make any sense to provide both in a findUnique ... More on stackoverflow.com
🌐 stackoverflow.com
Replace `findOne` with `findUnique`
Problem Today findOne depends on the unique constraints of the database to guarantee we'll find 0 or 1 records. According to the documentation: The findOne query lets you retrieve a single data... More on github.com
🌐 github.com
4
September 18, 2020
How to exactly use FindUnique with array (aka FindMany)
Okay, so I have prisma model like that, aka student refers to a lot of points (1 to many?) like 1 User and a lot of his posts in prisma examples model umo_student { person_ptr_id Int @id @default(a... More on github.com
🌐 github.com
2
1
How to findUnique on a relation field in Prisma?
I'm using Prisma with Postgres and I have a schema something like model User { id Int @id @default(autoincrement()) uuid String @u... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › kristenkinnearohlmann › basic-find-query-with-prisma-3hcb
Basic Find Query with Prisma - DEV Community
March 21, 2022 - const qry = <GUID value> const data = await prisma.user.findUnique({ where: { id: qry, }, select: { id: true, username: true, email: true, firstName: true, lastName: true }, });
🌐
DEV Community
dev.to › this-is-learning › its-prisma-time-select-3lie
It's Prisma Time - Select - DEV Community
January 11, 2022 - const post = await prisma.post.findUnique({ where: { id: 1, }, }); Ok, I think that's all for today. In the next article we are going to see how to paginate the results. See you soon guys!
🌐
Austinpeterson
austinpeterson.dev › articles › findUnique
Prisma: `findUnique` over `findFirst` - Austin Peterson
March 10, 2023 - Unique Identifiers: Use findUnique when you need to retrieve a record by a unique identifier, such as id or any other field marked as unique in your Prisma schema.
🌐
Medium
medium.com › @enayetflweb › organising-find-operations-in-prisma-with-typescript-8ef06ee53cce
Organising Find Operations in Prisma with TypeScript | by Md Enayetur Rahman | Medium
October 26, 2024 - Important Note on findUnique and findUniqueOrThrow · In Prisma, findUnique and findUniqueOrThrow can only be used with columns that are unique, like id. Non-unique columns, such as title, content, or authorName, cannot be used with findUnique since these fields may have duplicate values across ...
🌐
SabinTheDev
sabinadams.hashnode.dev › basic-crud-operations-in-prisma
Prisma and TypeScript CRUD Basics - Sabin Adams
June 21, 2024 - Check out this example of the findUnique function in action · const user = await prisma.user.findUnique({ where: { id: 3 } })
Find elsewhere
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
const categoriesOfPost: Category[] = await prisma.post .findUnique({ where: { id: 1 } }) .categories(); Note that you can chain as many queries as you like. In this example, the chaining starts at Profile and goes over User to Post: const posts: ...
🌐
Goprisma
goprisma.org › docs › walkthrough › find
Basic API – Prisma Client Go
October 22, 2024 - post, err := client.Post.FindUnique( db.Post.ID.Equals("123"), ).Exec(ctx) if errors.Is(err, db.ErrNotFound) { log.Printf("no record with id 123") } else if err != nil { log.Printf("error occurred: %s", err) }
🌐
GitHub
github.com › prisma › prisma › issues › 3697
Replace `findOne` with `findUnique` · Issue #3697 · prisma/prisma
September 18, 2020 - prisma.users.findOne({ where: { email: "alice@prisma.io" } }) Many people have been confused by this. They expect findOne to be more loose. More like: "Find the first record that matches my conditions." We're adding a new function called findFirst to solve for "Find the first record that matches my conditions." Here's the issue: #3676. We're also considering to eventually replace findOne with findUnique.
Author   prisma
🌐
Kristenkinnearohlmann
kristenkinnearohlmann.dev › prisma-basic-find-query
Basic Find Query with Prisma | Kristen's Developer Blog
March 20, 2022 - const qry = <GUID value> const data = await prisma.user.findUnique({ where: { id: qry, }, select: { id: true, username: true, email: true, firstName: true, lastName: true }, });
🌐
Paigeniedringhaus
paigeniedringhaus.com › blog › tips-and-tricks-for-using-the-prisma-orm
Tips and Tricks for Using the Prisma ORM | Paige Niedringhaus
We use Prisma’s standard findUnique API query on the Device table to find the specific device based on its device ID, and then inside of that findUnique() query, we add include: { fleets: true } to get all the fleet details that are related to that device. Here is what the data that comes back from the query looks like: Example device data with fleet info returned from query ·
🌐
Brendonovich
prisma.brendonovich.dev › reading-data › find
Find Queries - Prisma Client Rust - Brendonovich
use prisma::post; let posts: Option<post::Data> = client .post() .find_unique(post::id::equals("123".to_string())) .exec() .await .unwrap() Filtering on relations can be done in a similar way to filtering on scalars, it just takes some extra functions. For single relations, there is the is and is_not filters. The following example gets all comments whose post has the title "My Title":
🌐
Prisma
prisma.io › home › schema api › schema api › schema api
Prisma Schema API | Prisma Documentation
const user = await prisma.user.findUnique({ where: { firstName_lastName: { firstName: "Alice", lastName: "Smith", isAdmin: true, }, }, }); Relational databases · MongoDB · model User { id Int @default(autoincrement()) firstName String lastName ...
🌐
Prisma
prisma.io › home › query optimization › query optimization › query optimization › query optimization
Query optimization | Prisma Documentation
GraphQL runs a separate resolver function for every field, which can make it difficult to optimize a nested query. For example - the following GraphQL runs the allUsers resolver to get all users, and the posts resolver ...