From schema to answers
Design a Product model for a tea shop, then write the queries its pages need.
From pages to queries
Small projects like this one are where habits form. Naming each query, checking each result and keeping seed data rerunnable are the same habits that keep large applications easy to change years later.
Start from what the tea shop's pages show. The home page lists products in stock, the category page filters by category, product pages look up one item by its unique name, and the restock screen changes quantities. Each becomes one Prisma call, and writing them as small named functions keeps the pages simple and the queries reusable.
- Seed: createMany with all four products in one call.
- In stock: findMany({ where: { stock: { gt: 0 } }, orderBy: { name: "asc" } }).
- One product: findUnique({ where: { name } }).
- Restock: update with { stock: { increment: n } }.
- Add if missing: upsert with an empty update.
Log results as you go. Seeing the actual objects catches mistakes faster than reasoning about them.