Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is Prisma ORM?

Learn what Prisma ORM is, how its schema, generated client and migrations fit together, and when to choose it over raw SQL or other Node.js database tools.

Prisma ORM is a database toolkit for Node.js and TypeScript. You describe your data once, in a file called the Prisma schema, and Prisma gives you two things from that description: a type-safe client you use in your code to read and write data, and a migration system that keeps the real database in step with the schema.

If you have ever written SELECT * FROM users WHERE ... inside a template string and hoped you spelled every column correctly, you already know the problem Prisma tries to solve. With Prisma, a typo in a column name is a red squiggle in your editor, not a runtime error in production.

About the examples on this site. Prisma is an npm package that needs a database and a code generator, and our in-browser runner cannot install npm packages. So the Prisma code in this track is shown as read-only blocks (schema files, TypeScript, shell commands), and every runnable editor contains a clearly labelled stand-in: a few lines of plain Node.js that behave like the part of Prisma being discussed. Stand-ins teach the ideas; they are not Prisma. The track follows Prisma 7, so check the official documentation if a package name in your version differs.

The three big pieces

Prisma at a glance

Schema One file describes your models
Client Type-safe queries in code
Migrate Schema changes become SQL
Studio Browse data in a GUI

The schema is the source of truth for all four.

1 / 2
  1. The Prisma schema (schema.prisma) declares your database connection type, the generator, and your models. A model is roughly a table.
  2. Prisma Client is generated code. After you run prisma generate, you get a client whose methods and types match your models exactly: prisma.user.findMany(), prisma.post.create(...).
  3. Prisma Migrate compares the schema with the database and writes SQL migration files you can review, commit and apply anywhere.
  4. Prisma Studio is a small web app for browsing and editing rows while you develop.

A first look at the schema

A tiny schema for a blog looks like this:

PRISMA
generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider = "sqlite"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

You can read it almost like English: a User has an integer id that the database generates, a unique email, an optional name and many posts. A Post belongs to one author. You will study every line of this in the next chapters.

Where the types come from

Prisma reads the schema and generates TypeScript types. The ? in name String? becomes string | null; Int becomes number; relations become optional nested objects. This stand-in parses a miniature schema and prints the types, so you can see the mapping idea. It handles only the simple syntax in the example.

Node.js Stand-in: schema to TypeScript types

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Raw SQL versus an object API

Here is the same question asked two ways, against a real SQLite database (Node's built-in node:sqlite). The second function is a stand-in for what a client does: you pass an object, and a SQL statement with bound parameters is built for you.

Node.js Stand-in: object in, SQL out

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The real Prisma Client goes much further: it knows from the schema which fields exist, so your editor autocompletes them and the compiler rejects a field that is not there.

When Prisma is a good fit

  • You use TypeScript (or modern JavaScript) and want end-to-end types from database to API response.
  • You value a readable, single description of the data model and reviewable migrations.
  • You work with PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, CockroachDB or MongoDB (check the current supported list in the docs; MongoDB support has fewer features than SQL databases).

It is not magic. For heavy analytics or very unusual SQL you will still write SQL, and Prisma lets you do that safely with $queryRaw (see the chapter on raw SQL). Alternatives include Drizzle, Kysely, TypeORM, Sequelize and plain drivers; our track on TypeORM and Sequelize compares two older ORMs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Prisma generate from your schema.prisma file?

    prisma generate produces client code and types that mirror your models, so queries are checked by TypeScript.
  2. 2. In the schema, what does the type String? mean for a field?

    A question mark makes the field optional; in the generated TypeScript it becomes string | null.
  3. 3. Which Prisma piece turns schema changes into SQL files you can review?

    Prisma Migrate compares the schema with the database and writes migration SQL.
  4. 4. Why are the Prisma examples on this site read-only with stand-ins?

    Prisma needs npm packages, generated code and a database, so we show the real code read-only and run small labelled stand-ins.

Summary

  • Prisma ORM = schema + generated client + migrations (+ Studio).
  • The schema is the single source of truth; the client and migrations are derived from it.
  • Optional fields (String?) become T | null in TypeScript.
  • Stand-ins on this site illustrate ideas; they are not the real library.

Next: Installing Prisma and Setting Up a Project