Prisma — Next-Generation ORM for Node.js & TypeScript
Prisma is a next-generation ORM for Node.js and TypeScript supporting PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB, and CockroachDB. Type-safe database access with auto-generated client and intuitive schema language.
Instalación lista para agent
Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.
npx -y tokrepo@latest install 2f0e03dd-3567-11f1-9bc6-00163e2b0d79 --target codexEjecutar después de confirmar el plan con dry-run.
What it is
Prisma is a next-generation ORM for Node.js and TypeScript that replaces traditional ORMs with a schema-first approach. You define your data model in Prisma Schema Language, and Prisma generates a fully typed client, handles migrations, and provides a visual database browser (Prisma Studio). It supports PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB, and CockroachDB.
Prisma targets full-stack developers building applications with frameworks like Next.js, Remix, NestJS, or Express who want type-safe database access without writing raw SQL.
How it saves time or tokens
Prisma's auto-generated client means you never write boilerplate for database queries. The type system catches schema mismatches at compile time rather than runtime. Prisma Migrate generates SQL migration files from schema changes, eliminating manual migration writing. Prisma Studio provides a GUI for browsing and editing data without writing queries during development.
How to use
- Initialize Prisma in your project:
npm i -D prisma
npm i @prisma/client
npx prisma init
- Define your schema:
// prisma/schema.prisma
generator client { provider = "prisma-client-js" }
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
- Generate client and run migrations:
npx prisma migrate dev --name init
npx prisma generate
Example
Type-safe queries with relations:
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const userWithPosts = await prisma.user.findUnique({
where: { email: 'alice@example.com' },
include: { posts: true },
});
// userWithPosts is fully typed with User & { posts: Post[] }
Related on TokRepo
- Database tools — AI-assisted database utilities and ORMs
- AI coding tools — development frameworks and tools
Common pitfalls
- Prisma Client includes a query engine binary that adds to deployment size. For serverless environments, use the Prisma Accelerate proxy or the new Prisma Client with driver adapters.
- N+1 queries are easy to create with nested includes. Use Prisma's logging to identify and fix them during development.
- The Prisma Schema Language is custom and not TypeScript. Schema changes require running prisma generate to update the client, which can be forgotten in CI pipelines.
Preguntas frecuentes
Prisma uses its own schema language and generates a query client with a high-level API. Drizzle uses TypeScript for schemas and mirrors SQL syntax directly. Prisma prioritizes developer experience; Drizzle prioritizes SQL transparency and zero overhead.
Yes, with caveats. The Prisma Client includes a query engine binary that increases cold start times. Prisma Accelerate provides a connection pool proxy optimized for serverless. Driver adapters reduce bundle size.
Prisma Studio is a visual database browser that lets you view and edit data through a GUI. Run npx prisma studio to open it. It reads your schema and provides filtered, paginated views of your tables.
Yes. Prisma provides prisma.$queryRaw and prisma.$executeRaw for raw SQL queries. You can also use TypedSQL for type-safe raw queries that are checked against your schema.
Run npx prisma migrate deploy in your CI/CD pipeline. This applies pending migrations without generating new ones. Never run prisma migrate dev in production as it resets the database on schema drift.
Referencias (3)
- Prisma GitHub— Prisma supports PostgreSQL, MySQL, SQLite, MongoDB, and more
- Prisma Documentation— Schema-first approach with auto-generated typed client
- Prisma Migrate Docs— Prisma Migrate for database schema evolution
Relacionados en TokRepo
Discusión
Activos relacionados
Create T3 App — Full-Stack TypeScript Starter with Next.js
The best way to scaffold a full-stack, type-safe Next.js application with tRPC, Prisma, NextAuth.js, and Tailwind CSS baked in from the start.
Create T3 App — Full-Stack Typesafe Next.js Starter
Create T3 App is the fastest way to scaffold a full-stack, typesafe Next.js application using the T3 Stack: Next.js, TypeScript, tRPC, Prisma, Tailwind CSS, and NextAuth.js.
Payload CMS — Open Source Fullstack Next.js Headless CMS
Payload is the open-source headless CMS and app framework built on Next.js. TypeScript-first, code-configured, with instant admin panel, auth, and file uploads.
Next.js — The Full-Stack React Framework for the Web
Next.js is the most popular React framework for building full-stack web applications. It provides server-side rendering, static generation, API routes, file-based routing, and React Server Components — making React production-ready out of the box.