📝 Tutorials

What is Prisma? A Simple Explanation for Developers


Prisma is a TypeScript ORM (Object-Relational Mapper) for Node.js. It lets you interact with your database using TypeScript instead of writing raw SQL.

// Instead of: SELECT * FROM users WHERE email = 'alice@example.com'
const user = await prisma.user.findUnique({
  where: { email: 'alice@example.com' },
});

You get full type safety — your editor autocompletes table names, column names, and return types. If you rename a column, TypeScript catches every broken query at compile time.

How it works

  1. Define your database schema in prisma/schema.prisma:
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String
  posts Post[]
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId], references: [id])
  authorId Int
}
  1. Run migrations to create the tables:
npx prisma migrate dev --name init
  1. Query with full type safety:
const users = await prisma.user.findMany({
  include: { posts: true },
});
// users is typed as (User & { posts: Post[] })[]

Why developers use Prisma

  • Type safety — every query is type-checked. No runtime surprises.
  • Auto-generated client — Prisma generates a client from your schema with full IntelliSense.
  • Migrations — schema changes are tracked and versioned.
  • Works with any SQL database — PostgreSQL, MySQL, SQLite, SQL Server, CockroachDB.
  • Prisma Studio — visual database browser (npx prisma studio).

Prisma vs. alternatives

ToolApproachType safetyLearning curve
PrismaSchema-first ORMExcellentMedium
DrizzleSQL-like query builderExcellentLow
TypeORMDecorator-based ORMGoodMedium
KnexQuery builderManualLow
Raw SQLWrite SQL directlyNoneDepends on SQL skill

When to use Prisma

Good fit: TypeScript projects, teams that want type-safe database access, apps with relational data, rapid prototyping.

Not ideal: performance-critical queries where you need raw SQL control, very simple projects where an ORM is overkill, or if you prefer writing SQL.

For the full query reference, see the Prisma cheat sheet. See also: PostgreSQL cheat sheet