Sikau

Prisma · Day 5 · about 40 min

Project: Product catalogue

Schema plus queries for a small shop.

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.

The rest of this lesson

  • createMany and skipDuplicatesexplain
  • Upsert as "ensure exists"explain
  • Call for each pagematch
  • Seeding twicepredict
  • Tea shopchallenge
  • Badge quizquiz
  • Unit 1 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 15 lessons of Prisma