Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

API reference

Prisma API reference

Prisma ORM, schema and Client

Identifiers
105
With full guides
84
Types
6

Topics covered

  • Schema & models
  • Prisma Client
  • Migrations
  • Relations
  • Filtering & pagination
  • Transactions
  • Prisma Studio
  • Connection pooling

Class

NameWhat it does
PrismaClientPrismaClient is the generated, type-safe query interface for the models in a Prisma schema. In Prisma ORM v7, construct it with a database driver adapter before using generated model APIs.
DecimalPrisma.Decimal is Prisma Client's Decimal-field value type, backed by Decimal.js. Construct it with a numeric value and use Decimal.js arithmetic methods before passing it to a query.
PrismaClientKnownRequestErrorPrisma Client uses PrismaClientKnownRequestError for query-engine errors that are known to be related to a request, such as a unique-constraint violation. Its properties provide the error code, contextual metadata, message, and Client version.
PrismaClientValidationErrorPrismaClientValidationError is thrown when Prisma Client input validation fails, such as when required data is missing or a field receives an incompatible type. Its documented properties are message and clientVersion.

Function

NameWhat it does
prisma.findManyfindMany retrieves multiple records for a Prisma model. Query arguments can filter, shape, sort, and paginate the returned list.
prisma.findUniquefindUnique() 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.
prisma.createcreate() inserts one new database record through a generated Prisma Client model delegate. Supply the record values under data; nested writes can create related records in the same operation.
prisma.updateprisma.model.update() changes one existing record selected by a unique filter and returns the updated record. Its data object can include scalar changes and supported nested relation operations.
prisma.deletePrisma Client's delete removes one existing record selected by ID or another unique attribute. It returns the deleted record, with select or include available to control the returned shape.
prisma.upsertupsert updates a record when its unique where selector matches; otherwise, it creates one. It accepts separate update and create branches and may use a native database upsert when the documented criteria are satisfied.
$transaction$transaction runs multiple Prisma Client operations atomically. Use an array for sequential independent queries or a callback for interactive transaction logic.
prisma.$queryRaw$queryRaw executes one parameterized SQL statement and returns its records as an array. Use its tagged-template form, or Prisma.sql, to interpolate values more safely.
createManycreateMany() inserts multiple records of the same model in one transactional bulk operation. It returns the number of inserted records and can skip supported duplicate conflicts.
groupByPrisma Client groupBy() groups records by one or more fields and calculates aggregates for each group. It supports pre-group filtering with where, post-group filtering with having, and ordering grouped results.
aggregatePrisma Client's aggregate() calculates summary values such as averages, sums, minimums, and maximums over numeric model fields. Filtering, ordering, and limiting can be combined with the calculation.
Prisma.validatorPrisma.validator checks an object against a generated Prisma type and returns the type-safe object. It is commonly used to build reusable, schema-aware query parameters.
Prisma.sqlFunction
Prisma.rawPrisma.raw constructs raw SQL for use with Prisma Client raw-query methods. It is an unsafe escape hatch: manually assembled queries require database-specific parameter markers and careful handling of all dynamic input.
Prisma.emptyFunction
Prisma.joinFunction
withAcceleratewithAccelerate() is the Prisma Client extension entry point for Prisma Accelerate. Apply it with $extends() to enable Accelerate integration and query-level cache controls.
withPulseFunction

Const

NameWhat it does
includeinclude adds specified related records to a Prisma Client query result. The related data is returned nested under each parent record, and nested select can narrow the relation's fields.
selectPrisma Client's select option defines the scalar fields and relation fields included in a query result. It narrows both the returned payload and its generated TypeScript shape.
whereConst
equalsConst
notPrisma's not filter excludes records whose scalar field matches a specified value or condition. On nullable fields, it does not include NULL rows unless an OR branch explicitly includes them.
inConst
notInnotIn excludes records whose scalar field matches any value in a supplied list. Use it as a nested field filter in Prisma Client queries.
ltConst
ltelte filters Prisma Client query results to records whose field value is less than or equal to a specified value.
gtConst
gtegte filters Prisma Client query results to values greater than or equal to a supplied threshold. It is used inside a field condition in a where clause.
containscontains is a Prisma Client string filter that matches records whose selected field includes a specified substring. Combine it with mode: "insensitive" for case-insensitive matching.
startsWithstartsWith is a Prisma Client string filter that selects records whose field value begins with a specified prefix. Use it inside a string field’s where condition.
endsWithendsWith is a Prisma Client string filter for selecting records whose field value ends with a specified suffix. Put it inside the field condition of a where clause.
modeConst
searchPrisma Client’s search filter performs database-native full-text search on String fields. It supports MySQL and PostgreSQL, with PostgreSQL requiring the fullTextSearchPostgres preview feature.
someConst
everyConst
nonenone is a Prisma Client relation filter for to-many relations. It selects parent records with no related records matching the nested filter.
isConst
isNotisNot excludes records whose related to-one record matches the supplied nested filter. It is used inside Prisma Client where clauses, such as filtering posts whose author is not named Bob.
ANDConst
OROR combines alternative Prisma Client filter conditions. A record is selected when at least one condition in the array matches.
NOTNOT is a Prisma Client logical filter that excludes records matching a nested condition. It can be combined with other where operators to express compound inclusion and exclusion rules.
modelA Prisma model defines an application-domain entity in the Prisma schema. Prisma maps it to a table for relational databases or a collection for MongoDB.
datasourceConst
generatorgenerator is a Prisma schema block that configures assets produced by prisma generate. For the current Prisma Client generator, set provider and the required output path.
@id@id defines a model's single-field identifier. In relational databases it represents a single-field primary key; compound identifiers use @@id.
@unique@unique defines a single-field unique constraint in a Prisma model. It can identify records through a scalar field and automatically corresponds to a unique database index.
@default@default defines the value Prisma or the database uses when a scalar field is omitted during creation. It accepts literals, supported functions, and database-generated expressions.
@relation@relation defines metadata for a Prisma relation field, including how scalar foreign keys map to referenced fields. It also supports relation naming and referential actions.
@mapConst
@updatedAt@updatedAt automatically tracks when a record was last updated. Prisma Client manages the value for DateTime fields when the application does not provide one.
@db@db is Prisma’s native database type attribute. It refines a Prisma scalar by selecting the exact provider-specific database type used for the column.
enumConst
@@index@@index declares a database index on one or more fields of a Prisma model. Its options and supported behaviors vary by database provider.
@@unique@@unique defines a compound unique constraint across specified model fields. Every participating field must be mandatory, and Prisma adds a corresponding unique index.
@@map@@map maps a Prisma model to a differently named database table or MongoDB collection. It lets Prisma Client use a clean model name while preserving the database object's existing name.
@@id@@id defines a composite primary key using multiple scalar fields on a Prisma model. The combined field values identify each record and can be referenced through Prisma Client.
TypedSQLTypedSQL lets you write SQL in .sql files and use generated, fully typed functions from Prisma Client. It combines SQL flexibility with typed inputs and outputs.
prismaSchemaFolderprismaSchemaFolder enables a Prisma schema to be split across multiple .prisma files. Configure Prisma to use the directory containing those files, including schema.prisma with the generator block.
driverAdaptersdriverAdapters is a Prisma Client preview feature for using JavaScript database drivers through driver adapters. Adapters translate Prisma queries for supported database or serverless drivers.

Module

NameWhat it does
findUniquefindUnique() retrieves one record by ID, a unique field, or a compound unique key. It returns the matching record or null when no record exists, and supports selecting or including related data.
findUniqueOrThrowfindUniqueOrThrow retrieves one record using a unique lookup and throws PrismaClientKnownRequestError when no record matches. Unlike findUnique, its successful result is non-nullable.
findFirstfindFirst returns the first record matching a Prisma Client query. It returns null when nothing matches and supports the same query options as findMany.
findFirstOrThrowfindFirstOrThrow returns the first record matching a query and throws PrismaClientKnownRequestError when no record is found. Its result type is non-nullable.
findManyfindMany retrieves a list of records for a Prisma model. Use query arguments to filter, sort, paginate, or shape the returned data.
createPrisma Client's create operation inserts a new database record and returns it. It supports scalar values in data and nested creation of related records.
createManyAndReturnModule
updatePrisma Client’s update() changes one existing record selected by where and returns it. Use updateMany() for bulk changes, or updateManyAndReturn() when the updated objects are needed on supported databases.
updateManyupdateMany applies one set of field changes to every record matching a filter. It returns the number of records updated.
updateManyAndReturnupdateManyAndReturn() updates multiple matching records and returns the resulting objects. Prisma documents it for PostgreSQL, CockroachDB, and SQLite in Prisma ORM 6.2.0 and later.
upsertPrisma Client upsert updates a record when its unique where condition matches; otherwise, it creates one. It accepts separate update and create branches and may use a native database upsert when the query qualifies.
deleteModule
deleteManydeleteMany removes multiple records matching an optional filter. Prisma executes it transactionally and reports how many records were deleted.
countPrisma Client's count() returns the number of records matching optional filters, or counts non-null values for a selected field. Use it for model totals and filtered record counts.
$connect$connect() explicitly establishes Prisma Client's connection to the data source. It is usually unnecessary because Prisma connects lazily on the first query, but it can prepare the connection before requests arrive.
$disconnect$disconnect() asynchronously releases Prisma Client's database connections and shuts down its query engine. Use it mainly for finite scripts or temporary clients, not after every request in a long-running application.
$queryRaw$queryRaw runs a raw SQL query and returns its records as an array. Prefer its tagged-template form with interpolated parameters, which Prisma sends as a prepared statement.
$queryRawUnsafe$queryRawUnsafe executes raw SQL and returns query records. Use it only with trusted SQL structure or correctly parameterized values, because user-controlled interpolation can enable SQL injection.
$executeRaw$executeRaw runs one raw SQL operation and returns the number of affected rows, not records. Its tagged-template form supports parameterized values for safer execution.
$executeRawUnsafe$executeRawUnsafe executes a raw SQL string or template string and resolves to the number of affected rows. Its flexibility comes with a significant SQL-injection risk, especially when SQL text includes untrusted input.
$on$on() subscribes to Prisma Client's event-based log notifications. Configure a log level with emit: "event", then register a callback for events such as query.
$extendsPrisma Client’s $extends method creates a new extended client with custom model, client, result, or query behavior. Extensions can be supplied inline or defined separately and then attached.
$use$use was Prisma Client’s middleware API for code around queries, but it is deprecated and removed in current Prisma ORM. Use the client’s middleware array and named lifecycle hooks instead.

Pipe

NameWhat it does
orderByPrisma Client's orderBy option sorts query results by one or more fields. It supports ascending or descending directions, multiple criteria, and ordering through relations.
takepipe(stage) appends a manually constructed MongoDB pipeline stage when typed pipeline methods do not cover an operation. The existing row type is retained.
skipPrisma.skip is a Prisma-provided symbol that explicitly omits a field from a Prisma Client query. Use it instead of undefined when an optional input should not be included.
cursorPrisma cursor pagination uses a unique, sequential field to bookmark a position and fetch records before or after it. Combine cursor with take, orderBy, and usually skip: 1 for forward pages.
distinctPipe
dataPipe
omitPrisma Client's omit option excludes selected model fields from returned results. It can be applied globally on the client or locally to one query, making it useful for hiding sensitive fields such as passwords.
relationLoadStrategyrelationLoadStrategy selects how Prisma loads related records for a relation query. Use join for a database-level single-query strategy or query for multiple queries merged in application code.

Command

NameWhat it does
prisma generateGenerates artifacts such as Prisma Client from the generator and data model blocks in a Prisma schema. It can target a custom schema, select generators, generate typed SQL, or watch for changes.
prisma migrate devprisma migrate dev creates and applies migrations while developing. It uses a shadow database to detect drift and requires a development environment.
prisma migrate deployApplies all pending Prisma Migrate migrations to a staging or production database, creating the database if necessary. It is designed for automated deployment environments.
prisma migrate resetResets a development database or schema and reapplies all migrations, destroying existing data. It requires confirmation unless --force is supplied.
prisma db pushprisma db push synchronizes the Prisma schema directly to a database without migrations. It is intended mainly for prototyping and local development, and in Prisma v7 client generation must be run separately when needed.
prisma db pullprisma db pull introspects a database and updates the Prisma schema with models matching its current structure. It reads the connection configuration from Prisma config and supports options for selecting, printing, or replacing schema output.
prisma db seedprisma db seed runs the command configured in migrations.seed to populate a database with initial or test data. In Prisma ORM v7, it must be invoked explicitly.
prisma studioprisma studio starts a local web interface for interactively browsing and managing database data. It can use Prisma project configuration or a direct database URL.
prisma formatprisma format validates and reformats a Prisma schema, saving the result. Use --schema or --config when the schema or Prisma configuration is stored at a custom path.
prisma validateprisma validate checks a Prisma schema for Prisma Schema Language syntax errors and configuration issues. Optional flags let you select a custom schema or Prisma config file.

Search across every package and filter by type in your dashboard.

Start learning