Fetch by ID
Load one account by its primary key during a request.
Prisma · Function
findUnique() retrieves one Prisma record by an ID, unique field, or compound unique key. It can shape the result with select/include and returns null when no record matches.
Call the model delegate's findUnique method with a where filter containing an ID, unique field, or compound unique key. The method returns one matching record, optionally restricted with select or expanded with include; if no record matches, the result is null.
prisma.<model>.findUnique({ where, select?, include? })| Name | Type | Description |
|---|---|---|
args | ModelFindUniqueArgs | Options object containing where and optional result-shaping or relation-loading arguments; the exact generated type depends on the model. |
A Promise resolving to the matching model record, shaped by select/include, or null when no record matches.
const user = await prisma.user.findUnique({
where: { email: "alice@prisma.io" },
select: { id: true, name: true }
});Retrieves the selected fields for the user whose email is unique.
Load one account by its primary key during a request.
Look up a user by an email address declared unique in the schema.
Retrieve an entity identified by multiple fields under a compound constraint.
Return only fields needed by an API response.
findUnique retrieves at most one record using a unique identifier, such as an ID or unique attribute. If no matching record exists, it returns null.
Follow-up: How would you retrieve only selected columns? Add a select object, for example select: { name: true, profileViews: true }.
Pass the model delegate a where object whose value identifies a unique record, such as { id: 42 } or { email: "alice@prisma.io" }. A compound unique constraint is represented by its generated or custom compound-key field containing the constituent values.
Follow-up: What alternative exists when missing data should be exceptional? Use findUniqueOrThrow(), which retrieves the record in the same way but throws if it is absent.
Use select to specify returned fields or include to request related records. These options shape the result while the where clause still determines the unique record being queried.
Follow-up: What performance behavior can occur across repeated lookups? Prisma Client's dataloader can automatically batch findUnique queries.
findUniqueOrThrow()selectinclude@@unique@@id