| sidebar_position | 2 |
|---|---|
| description | Find API |
import StackBlitzGithub from '@site/src/components/StackBlitzGithub'; import SelectIncludeOmit from './_select-include-omit.md'; import AvailableSince from '../../_components/AvailableSince';
The find series of APIs are used to query records from the database. It has the following methods:
-
findManyFind multiple records that match the query criteria.
-
findUniqueFind a single record with a unique criteria.
-
findFirstFind the first record that matches the query criteria.
-
findUniqueOrThrowSimilar to
findUnique, but throws an error if no record is found. -
findFirstOrThrowSimilar to
findFirst, but throws an error if no record is found. -
existsCheck if any record exists that matches the query criteria. More performant than using
findFirstorcount.
The API provides a very flexible set of filtering options. We've put it into a dedicated document.
Use the orderBy field to control the sort field, direction, and null field placement. Sorting is not supported for findUnique and findUniqueOrThrow.
You can use two strategies for pagination: offset-based or cursor-based. Pagination is not supported for findUnique and findUniqueOrThrow.
You can use the following fields to control what fields are returned in the result:
You can use the distinct field to find distinct rows based on specific fields. One row for each unique combination of the specified fields will be returned. The implementation relies on SQL DISTINCT ON, so it's not available for SQLite provider.
// returns one Post for each unique authorId
await db.post.findMany({ distinct: ['authorId'] });