Queries
In this section
CRUD
This page describes how to perform CRUD operations with your generated Prisma Client API. CRUD is an acronym that stands for:
Select fields
Overview
Relation queries
A key feature of Prisma Client is the ability to query relations between two or more models. Relation queries include:
Filtering and Sorting
Prisma Client supports filtering with the where query option, and sorting with the orderBy query option.
Pagination
Prisma Client supports both offset pagination and cursor-based pagination.
Aggregation, grouping, and summarizing
Prisma Client allows you to count records, aggregate number fields, and select distinct field values.
Transactions and batch queries
A database transaction refers to a sequence of read/write operations that are guaranteed to either succeed or fail as a whole. This section describes the ways in which the Prisma Client API supports transactions.
Full-text search
Prisma Client supports full-text search for PostgreSQL databases in versions 2.30.0 and later, and MySQL databases in versions 3.8.0 and later. With full-text search (FTS) enabled, you can add search functionality to your application by searching for text within a database column.
Custom validation
You can add runtime validation for your user input for Prisma Client queries in one of the following ways:
Computed fields
Computed fields allow you to derive a new field based on existing data. A common example is when you want to compute a full name. In your database, you may only store the first and last name, but you can define a function that computes a full name by combining the first and last name. Computed fields are read-only and stored in your application's memory, not in your database.
Excluding fields
By default Prisma Client returns all fields from a model. You can use select to narrow the result set, but that can be unwieldy if you have a large model and you only want to exclude a small number of fields.
Custom models
As your application grows, you may find the need to group related logic together. We suggest either:
Case sensitivity
Case sensitivity affects filtering and sorting of data, and is determined by your database collation. Sorting and filtering data yields different results depending on your settings:
Query optimization
This guide shows how to identify and optimize query performance, debug performance issues, and address common challenges.