One page

Prisma ORM cheat sheet

What to keep at hand. If a line is not clear, go back to the matching lesson in the course.

Open the course: Prisma ORM

Queries

WhatHow
Listprisma.order.findMany({ where: { status: "paid" }, take: 20 })
Oneprisma.user.findUnique({ where: { email } })
Createprisma.user.create({ data: { email, name } })
With a relationinclude: { orders: true }
Counterdata: { views: { increment: 1 } }

Schema and migrations

WhatHow
Generate the clientnpx prisma generate
New migrationnpx prisma migrate dev --name add_phone
On the servernpx prisma migrate deploy
Transactionprisma.$transaction(async (tx) => { … })

More queries

WhatHow
Search{ title: { contains: q, mode: "insensitive" } }
Cursor{ take: 20, skip: 1, cursor: { id: after } }
Linkuser: { connect: { id: userId } }
Create or updateprisma.user.upsert({ where, update, create })
Email takenerr.code === "P2002"
Raw SQLprisma.$queryRaw`SELECT … WHERE id = ${id}`

Other cheat sheets