Prisma ORM
Overview
Prisma is a next-generation ORM for Node.js and TypeScript. You declare your data model in a single schema.prisma file using its schema DSL, then Prisma generates a fully type-safe query client and manages SQL migrations. Read this when you need ergonomic, type-checked database access against PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB, or CockroachDB.
Official sources
Install / setup
npm install prisma @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg pg dotenv
npx prisma init --output ../generated/prisma
Core concepts
- Prisma schema (
schema.prisma): the single source of truth — declares the datasource, generator, and model definitions in Prisma's DSL.
- Prisma Client: an auto-generated, type-safe query builder; regenerate it with
npx prisma generate after schema changes.
- Prisma Migrate: turns schema changes into SQL migration files via
npx prisma migrate dev.
- Models, fields, and relations: each
model maps to a table; relation fields and @relation express foreign keys.
- Prisma Studio: a GUI to browse and edit data, launched with
npx prisma studio.
Best practices
- Keep the schema as the source of truth and commit migration files; use
migrate dev in development and migrate deploy in production (per Prisma docs).
- Run
prisma generate whenever the schema changes so the client's types stay in sync.
- Instantiate a single
PrismaClient and reuse it; avoid creating many instances which exhausts the connection pool.
- Use
select/include to fetch only needed fields and relations rather than over-fetching.
Common pitfalls
- Instantiating
PrismaClient per request (common in serverless/hot-reload) → exhausts connections; use a shared singleton.
- Forgetting to run
prisma generate after editing the schema → stale types and runtime mismatches; regenerate after every change.
Examples
import { PrismaClient } from './generated/prisma'
const prisma = new PrismaClient()
const user = await prisma.user.create({
data: { email: 'a@example.com', name: 'Ada' },
})
const users = await prisma.user.findMany({ where: { name: 'Ada' } })
Further reading
Related skills
- ../drizzle — lighter-weight TypeScript SQL ORM alternative
- ../typeorm — decorator-based TS/JS ORM alternative
1---2name: prisma3description: Type-safe TS/JS ORM with a declarative schema DSL, auto-generated client, and migrations; consult when modeling data in Node.js.4domain: stack5category: orm6tags: [orm, typescript, nodejs, database, migrations, postgresql]7official_sources:8 - https://www.prisma.io/docs9 - https://github.com/prisma/prisma10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/prisma13---1415# Prisma ORM1617## Overview18Prisma is a next-generation ORM for Node.js and TypeScript. You declare your data model in a single `schema.prisma` file using its schema DSL, then Prisma generates a fully type-safe query client and manages SQL migrations. Read this when you need ergonomic, type-checked database access against PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB, or CockroachDB.1920## Official sources21- Docs: https://www.prisma.io/docs22- Repo: https://github.com/prisma/prisma23- Install / quickstart: https://www.prisma.io/docs/getting-started/quickstart2425## Install / setup26```bash27npm install prisma @types/pg --save-dev28npm install @prisma/client @prisma/adapter-pg pg dotenv29npx prisma init --output ../generated/prisma30```3132## Core concepts33- **Prisma schema (`schema.prisma`)**: the single source of truth — declares the datasource, generator, and `model` definitions in Prisma's DSL.34- **Prisma Client**: an auto-generated, type-safe query builder; regenerate it with `npx prisma generate` after schema changes.35- **Prisma Migrate**: turns schema changes into SQL migration files via `npx prisma migrate dev`.36- **Models, fields, and relations**: each `model` maps to a table; relation fields and `@relation` express foreign keys.37- **Prisma Studio**: a GUI to browse and edit data, launched with `npx prisma studio`.3839## Best practices40- Keep the schema as the source of truth and commit migration files; use `migrate dev` in development and `migrate deploy` in production (per Prisma docs).41- Run `prisma generate` whenever the schema changes so the client's types stay in sync.42- Instantiate a single `PrismaClient` and reuse it; avoid creating many instances which exhausts the connection pool.43- Use `select`/`include` to fetch only needed fields and relations rather than over-fetching.4445## Common pitfalls46- Instantiating `PrismaClient` per request (common in serverless/hot-reload) → exhausts connections; use a shared singleton.47- Forgetting to run `prisma generate` after editing the schema → stale types and runtime mismatches; regenerate after every change.4849## Examples50```ts51import { PrismaClient } from './generated/prisma'52const prisma = new PrismaClient()5354const user = await prisma.user.create({55 data: { email: 'a@example.com', name: 'Ada' },56})57const users = await prisma.user.findMany({ where: { name: 'Ada' } })58```5960## Further reading61- https://www.prisma.io/docs/orm/prisma-schema — Prisma schema reference62- https://www.prisma.io/docs/orm/prisma-migrate — Prisma Migrate guide6364## Related skills65- ../drizzle — lighter-weight TypeScript SQL ORM alternative66- ../typeorm — decorator-based TS/JS ORM alternative