StoicBuilder

HandbookII the ForumORMs

IIthe Forum, The shape of an app

ORMs

1 min readUpdated 28 November

In plain words

An ORM is a library, such as Prisma or Drizzle, that lets your code work with database rows as ordinary objects and turns that into SQL for you.

Where you see it

A prisma/schema.prisma file, or a db/schema.ts full of pgTable calls if your agent chose Drizzle. In the code you'll see lines like prisma.order.findMany() where you might have expected SQL.

app/orders/page.tsxserver
const orders = await prisma.order.findMany({ where: { userId: user.id }, include: { items: true }, orderBy: { createdAt: "desc" },});
Prisma turns this into SQL, runs it against Postgres and hands back plain objects.

What goes wrong

  1. Two ways of talking to the same database

    A project that already queries Supabase directly sometimes gains Prisma too, after one vague prompt. You now have two descriptions of the same tables, and they can disagree.

  2. Editing the schema file and stopping there

    Changing schema.prisma doesn't change the database. Until a migration runs, the code and the database describe different tables.

  3. A query inside a loop

    Loading 50 orders and then fetching each one's items separately sends 51 queries. Ask for the related data in the same query.

    for (const o of orders) o.items = await prisma.item.findMany({ where: { orderId: o.id } });

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Tell me whether this project uses an ORM, which one, and where its schema file lives. Use only that one way of talking to the database, and never put a query inside a loop.

Quick check

Sign in to earn +10 XP for it

QuickBite's order history takes eight seconds to show 50 orders. The code loads the orders, then fetches each order's items one by one. Likely fix?

Got a prompt that touches ORMs?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.