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
includeandselect.
Example
Interview questions
1. How does Prisma provide type safety?
prisma generatereads the schema and builds a client with types for models, filters and results. A wrong field name is caught at compile time.2. What is the N+1 problem in Prisma?
A separate query for related data per item. Avoid it with
include/selector batching by ids.3. How does
migrate devdiffer frommigrate deploy?devcreates new migrations during development and may reset the dev database.deployonly applies already created migrations in production.
Related technologies
- TypeScriptA superset of JavaScript with static types that compiles to plain JS.
- Node.jsA server-side JavaScript runtime built on the V8 engine with an event-driven, non-blocking I/O model.
- PostgreSQLA powerful open source relational database with extensions, JSONB, full-text search and strong SQL support.
- MySQLOne of the most widespread relational databases, the foundation of many web projects and the LAMP stack.
- SQLiteAn embedded serverless database in a single file: the most widely deployed database in the world.
- MongoDBThe most popular document NoSQL database, storing data as JSON-like documents (BSON).
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).