Prisma ORM Cheatsheet

Quick reference for Prisma ORM: models, CRUD operations, filtering, sorting, relations, aggregation, transactions, and migrations.

FeatureDescriptionExampleCategory
modelDefine a database modelmodel User { id Int @id @default(autoincrement()) name String }Models
enumDefine an enumenum Role { USER ADMIN }Models
findMany()Retrieve multiple recordsprisma.user.findMany();CRUD
findUnique()Retrieve one record by unique fieldprisma.user.findUnique({ where: { id: 1 } });CRUD
create()Create a recordprisma.user.create({ data: { name: "Alice" } });CRUD
update()Update a recordprisma.user.update({ where: { id: 1 }, data: { name: "Bob" } });CRUD
delete()Delete a recordprisma.user.delete({ where: { id: 1 } });CRUD
whereFilter recordsprisma.user.findMany({ where: { name: "Alice" } });Filtering & Sorting
orderBySort resultsprisma.user.findMany({ orderBy: { name: "asc" } });Filtering & Sorting
take / skipPaginationprisma.user.findMany({ take: 10, skip: 20 });Filtering & Sorting
includeInclude related modelsprisma.user.findMany({ include: { posts: true } });Relations
selectSelect specific fieldsprisma.user.findMany({ select: { id: true, name: true } });Relations
count()Count recordsprisma.user.count({ where: { active: true } });Aggregation
aggregate()Aggregation queriesprisma.user.aggregate({ _avg: { age: true } });Aggregation
groupBy()Group recordsprisma.user.groupBy({ by: ["role"], _count: { id: true } });Aggregation
$transactionRun multiple queries atomicallyprisma.$transaction([prisma.user.create({ data: {...} }), prisma.post.create({ data: {...} })]);Transactions
prisma migrate devRun migration during developmentnpx prisma migrate dev --name initMigrations & CLI
prisma db pushPush schema changes to databasenpx prisma db pushMigrations & CLI
prisma studioOpen Prisma GUInpx prisma studioMigrations & CLI