Backend essentialsIntermediate6h

ORMs & queries.

Prisma or Drizzle: typed database access from TypeScript.

What is an ORM?

An ORM (or query builder) lets you read and write the database from TypeScript with types instead of raw SQL strings. Prisma and Drizzle are the popular choices: you define your schema once and get typed, autocompleted queries — and types that flow into the rest of your stack.

Why it matters

For full-stack TypeScript, a typed ORM is a key part of end-to-end type safety: a column rename becomes a compile error everywhere it is used, not a runtime surprise. It also parameterizes queries by default, closing the injection risk. This node connects the database to the seam stage's type flow.

What to learn

  • Defining a schema with Prisma or Drizzle
  • Typed queries and the generated client
  • Relations and including related data
  • Migrations from the schema
  • Raw SQL escape hatches when needed
  • Avoiding the N+1 query problem
  • How ORM types feed end-to-end typing

Common pitfall

The N+1 query problem: fetching a list, then firing one more query per item for a relation, turning 1 query into 101. ORMs make this easy to do by accident in a loop. Use the ORM's include/join features to fetch related data in one query, and watch your query counts under real data.

Resources

Primary (free):

Practice

Define a schema with two related tables in Prisma or Drizzle, run a migration, and write typed queries to create and read data, including the relation in one query. Trigger an N+1 by querying in a loop, then fix it with an include. Done when related data loads in a single query and a column rename is a compile error.

Outcomes

  • Define a schema and generate a typed client.
  • Write typed queries with relations.
  • Avoid the N+1 problem with includes/joins.
  • Let ORM types feed end-to-end type safety.
Back to Full-Stack roadmap