On this page

Technology

Prisma

Prisma is an open-source ORM for Node.js and TypeScript: you describe the data model in one schema, and it generates a typed client and the migrations. I use it with PostgreSQL in my products and on this site

Type
Technology
Official site
prisma.io
In my work
Projects 1 · Tools 1
Published

What is Prisma and how do I use it with PostgreSQL?

With Prisma the database schema and the TypeScript code cannot drift apart: a renamed column breaks the build, not the production server

Key facts

Type
Open-source ORM for Node.js and TypeScript ·
Databases
PostgreSQL, MySQL, SQLite and others ·

How I use Prisma

  • One schema for the whole product. Users, matches, content and payments of my multiplayer platform and of this site are described in one Prisma schema on PostgreSQL; the typed client follows every change. Read the case study.
  • Migrations I can read. Each change is a SQL migration in the repository. Before a release I apply it to a throwaway local database and compare the result with the schema.
  • Releases with a way back. I prefer migrations that only add tables and columns, so the previous release still works if a new one has to be rolled back. Production applies them after an encrypted backup.

When I choose Prisma and its limits

Prisma fits products where most queries are ordinary reads and writes and the team wants types everywhere. It removes a whole class of mistakes and makes migrations part of the code review.

For heavy reports and unusual queries I write SQL directly; Prisma allows that in the same project. A destructive change, such as dropping a table, still needs a plan and a backup: no tool makes it safe on its own.

Used together with

Sources

  1. Prisma Documentation — Prisma ·

Contact

Have an idea? Let’s make it work