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 ORMQueries
| What | How |
|---|---|
| List | prisma.order.findMany({ where: { status: "paid" }, take: 20 }) |
| One | prisma.user.findUnique({ where: { email } }) |
| Create | prisma.user.create({ data: { email, name } }) |
| With a relation | include: { orders: true } |
| Counter | data: { views: { increment: 1 } } |
Schema and migrations
| What | How |
|---|---|
| Generate the client | npx prisma generate |
| New migration | npx prisma migrate dev --name add_phone |
| On the server | npx prisma migrate deploy |
| Transaction | prisma.$transaction(async (tx) => { … }) |
More queries
| What | How |
|---|---|
| Search | { title: { contains: q, mode: "insensitive" } } |
| Cursor | { take: 20, skip: 1, cursor: { id: after } } |
| Link | user: { connect: { id: userId } } |
| Create or update | prisma.user.upsert({ where, update, create }) |
| Email taken | err.code === "P2002" |
| Raw SQL | prisma.$queryRaw`SELECT … WHERE id = ${id}` |