Stop 08 · ORMs & Query BuildersTopics · 2/10

Prisma

Part of the Backend Developer Roadmap

In short

Prisma is a popular TypeScript ORM. You describe your tables in one schema file and it generates a fully typed client, so a typo in a column name fails before the code even runs.

A modern, type-safe ORM for Node.js/TypeScript with an intuitive schema file, auto-generated client, and excellent developer experience — currently one of the most popular choices.

The blob as a tailor holds a measuring tape beside a neatly fitted kurta on a dress form.

Think of it like this

The tailor's measurements

A good tailor takes your measurements once, notes them in his book, and every kurta he stitches fits. Prisma works the same way: you write the schema once in schema.prisma, and it stitches a client that fits your database exactly, every field and type known.

Watch it happen

The Prisma workflow

Schema
Migrate
Generate
Query

1/4Describe models in schema.prisma: a User has an id, an email and many posts.

The big ideas

What you need to know

One schema file

schema.prisma holds your models, relations and database settings in a readable format.

Generated, typed client

Every query result has an exact TypeScript type, including only the fields you selected.

Prisma Migrate

Change the schema, run migrate dev, and Prisma writes the SQL migration for you.

Prisma Studio

npx prisma studio opens a table editor in your browser. Handy for quick checks on your data.

See it in code

Walk through the code

ts
1// schema.prisma2// model User {3//   id    Int    @id @default(autoincrement())4//   email String @unique5//   posts Post[]6// }7 8const user = await prisma.user.create({9  data: {10    email: "riya@college.edu",11    posts: { create: [{ title: "My first blog" }] },12  },13  include: { posts: true },14});15console.log(user.posts[0].title); // fully typed

1/4The model in schema.prisma. @id and @unique become a primary key and a unique constraint.

Start with npx prisma init and follow its output. Setup details change between major versions, so check the docs for yours.

Save yourself the pain

Common mistakes

Oops

Creating a new PrismaClient inside every request handler.

Do this instead

Create one client and reuse it. Each instance opens its own connection pool.

Oops

Changing the database by hand and forgetting the schema.

Do this instead

Change schema.prisma and run a migration, or run prisma db pull to sync the schema from the database.

Your mission

Blog with Prisma

~30 min

Quick check

You rename a field in schema.prisma but don't regenerate the client. What does your code see?

Go deeper

  1. 1Define a schema in `schema.prisma` and generate the client.
  2. 2Practice type-safe queries and notice how your editor autocompletes based on your schema.
  3. 3Run `prisma migrate` to apply a schema change to your database.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge