CRUD Operations
Prisma Client provides intuitive methods for creating, reading, updating, and deleting records in your database.Create
create()
Create a single record:createMany()
Create multiple records in a single operation:createMany does not return created records, only the count. It also doesn’t support nested creates.
Read
findUnique()
Find a single record by unique field:findUniqueOrThrow()
Throws error if record not found:findFirst()
Find first matching record:findFirstOrThrow()
Throws error if no match found:findMany()
Find multiple records:Update
update()
Update a single record:increment: Add to numeric fielddecrement: Subtract from numeric fieldmultiply: Multiply numeric fielddivide: Divide numeric field
/home/daytona/workspace/source/packages/client/tests/functional/0-legacy-ports/atomic-increment-decrement/
Update relations:
updateMany()
Update multiple records:updateMany returns only the count, not the updated records.
upsert()
Update existing record or create if it doesn’t exist:Delete
delete()
Delete a single record:deleteMany()
Delete multiple records:Fluent API
Certain operations return a fluent API for traversing relations:findUnique()findUniqueOrThrow()findFirst()findFirstOrThrow()create()update()upsert()delete()
/home/daytona/workspace/source/packages/client/src/runtime/core/model/applyModel.ts:24-33
Field Selection
All read and write operations support field selection:select
Choose specific fields:include
Include relations:select and include together on the same level.
See Relations for more details.
Return Types
Operation return types:| Operation | Return Type | Notes |
|---|---|---|
create() | Model | Single record |
createMany() | { count: number } | Count only |
findUnique() | Model | null | Null if not found |
findUniqueOrThrow() | Model | Throws if not found |
findFirst() | Model | null | Null if not found |
findFirstOrThrow() | Model | Throws if not found |
findMany() | Model[] | Empty array if none |
update() | Model | Throws if not found |
updateMany() | { count: number } | Count only |
upsert() | Model | Never null |
delete() | Model | Throws if not found |
deleteMany() | { count: number } | Count only |
/home/daytona/workspace/source/packages/client/src/runtime/core/model/applyModel.ts:63-126
Next Steps
Queries
Learn advanced query patterns
Relations
Work with relations and nested data
Filtering
Filter and sort your data
Transactions
Ensure data consistency with transactions