Find
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.
Basic usage
Filtering
The API provides a very flexible set of filtering options. We've put it into a dedicated section.
Sorting
Use the sort field to control the sort field, direction, and null field placement. Sorting is not supported for findUnique and findUniqueOrThrow.
Pagination
You can use two strategies for pagination: offset-based or cursor-based. Pagination is not supported for findUnique and findUniqueOrThrow.
Field selection
You can use the following fields to control what fields are returned in the result:
-
selectAn object specifying the fields to include in the result. Setting a field to
truemeans to include it. If a field is a relation, you can provide an nested object to further specify which fields of the relation to include.This field is optional. If not provided, all non-relation fields are included by default. The
includefield is mutually exclusive with theselectfield. -
includeAn object specifying the relations to include in the result. Setting a relation to
truemeans to include it. You can pass an object to further choose what fields/relations are included for the relation, and/or awhereclause to filter the included relation records.This field is optional. If not provided, no relations are included by default. The
includefield is mutually exclusive with theselectfield. -
omitAn object specifying the fields to omit from the result. Setting a field to
truemeans to omit it. Only applicable to non-relation fields.This field is optional. If not provided, no fields are omitted by default. The
omitfield is mutually exclusive with theselectfield.
Finding distinct rows
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 uses SQL DISTINCT ON if it's supported by the dialect, otherwise falls back to in-memory deduplication.