Backend

Prisma

An ORM for Node.js and TypeScript with a schema file, a generated type-safe client and migrations.

What it is

In Prisma you describe the data model in a schema.prisma file. A client is generated from it, with autocomplete and types matching your tables.

Prisma Migrate creates SQL migrations from schema changes. It supports PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. Prisma Studio browses the data.

The client keeps you from writing arbitrary invalid queries, and tricky cases can use raw SQL. For very complex reports a query builder is sometimes handier.

Use it when

  • TypeScript backends that value type safety and a quick start.
  • You need migrations and a clear schema in one place.
  • The team does not want to hand-write SQL for typical CRUD.

Avoid it when

  • Heavy analytics with window functions: plain SQL or a query builder is better.
  • The project is not in JS/TS.

Key concepts

schema.prisma
The single source of truth for models, relations and the database provider.
Prisma Client
A generated type-safe query API.
Migrate
Generates and applies SQL migrations.
Relations
Links between models with include and select.

Example

Users with published posts.

Interview questions

  1. 1. How does Prisma provide type safety?

    prisma generate reads the schema and builds a client with types for models, filters and results. A wrong field name is caught at compile time.

  2. 2. What is the N+1 problem in Prisma?

    A separate query for related data per item. Avoid it with include/select or batching by ids.

  3. 3. How does migrate dev differ from migrate deploy?

    dev creates new migrations during development and may reset the dev database. deploy only applies already created migrations in production.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).