Search pages, the Prisma way
A menu search with filters and pages needs flexible conditions. Prisma's where mirrors SQL's power with plain objects — and the same shape works across every query method.
where, orderBy, skip, take
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
console.log(await prisma.dish.findMany({
where: {
OR: [{ name: { contains: "MOMO", mode: "insensitive" } }, { tags: { has: "popular" } }],
price: { gte: 100, lte: 250 },
NOT: { category: "drink" },
},
orderBy: [{ category: "asc" }, { price: "desc" }],
select: { name: true, category: true, price: true },
}));
const page = 2, perPage = 3;
console.log(await prisma.dish.findMany({ orderBy: { id: "asc" }, skip: (page - 1) * perPage, take: perPage, select: { id: true, name: true } }));
console.log(await prisma.dish.findMany({ where: { category: { in: ["snack", "drink"] } }, select: { name: true } }));