Find
The find
series of APIs are used to query records from the database. It has the following methods:
-
findMany
Find multiple records that match the query criteria.
-
findUnique
Find a single record with a unique criteria.
-
findFirst
Find the first record that matches the query criteria.
-
findUniqueOrThrow
Similar to
findUnique
, but throws an error if no record is found. -
findFirstOrThrow
Similar to
findFirst
, but throws an error if no record is found.
Basic usage
- Interactive Sample
- Plain Code
Loading...
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
.
- Interactive Sample
- Plain Code
Loading...
Pagination
You can use two strategies for pagination: offset-based or cursor-based. Pagination is not supported for findUnique
and findUniqueOrThrow
.
- Interactive Sample
- Plain Code
Loading...
Field selection
You can use the following fields to control what fields are returned in the result:
-
select
An object specifying the fields to include in the result. Setting a field to
true
means 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
include
field is mutually exclusive with theselect
field. -
include
An object specifying the relations to include in the result. Setting a relation to
true
means to include it. You can pass an object to further choose what fields/relations are included for the relation, and/or awhere
clause to filter the included relation records.This field is optional. If not provided, no relations are included by default. The
include
field is mutually exclusive with theselect
field. -
omit
An object specifying the fields to omit from the result. Setting a field to
true
means to omit it. Only applicable to non-relation fields.This field is optional. If not provided, no fields are omitted by default. The
omit
field is mutually exclusive with theselect
field.
- Interactive Sample
- Plain Code
Loading...
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.
- Interactive Sample
- Plain Code
Loading...