ScriptsApr 11, 2026·1 min read

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.

SC
Script Depot · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

npm i -D prisma
npm i @prisma/client
npx prisma init

Define 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
  posts Post[]
}

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

Generate & migrate:

npx prisma migrate dev --name init
npx prisma generate

Query:

import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

const users = await prisma.user.findMany({
  include: { posts: true },
});
Intro

Prisma is a next-generation ORM for Node.js & TypeScript. Fully type-safe database access with auto-generated client from the Prisma schema. Supports PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB, and CockroachDB.

What Prisma Does

  • Prisma Schema — single source of truth for data model
  • Prisma Client — auto-generated, type-safe query builder
  • Prisma Migrate — declarative migrations from schema changes
  • Prisma Studio — GUI browser for database
  • Relation queriesinclude and select for nested data
  • Transactions — interactive and batch

Architecture

Schema → Prisma Engine (Rust) → Database. The TypeScript client wraps a Rust binary (or WASM in edge runtimes) that handles query compilation, connection pooling, and protocol. Types are generated from the schema on prisma generate.

Self-Hosting

Prisma is a library, not a service. Ships with your app. For connection pooling in serverless, use Prisma Accelerate (hosted) or PgBouncer/Supavisor self-hosted.

# Production
npx prisma migrate deploy
node dist/server.js

Key Features

  • Fully type-safe queries
  • Declarative schema (.prisma file)
  • Auto-migrations
  • Multi-database support
  • Prisma Studio (GUI)
  • Edge runtime support (Cloudflare, Vercel)
  • Interactive transactions
  • Full-text search (PostgreSQL)

Comparison

ORM Type Safety Migrations Performance Query Style
Prisma Excellent Auto Good Builder
Drizzle Excellent Manual Fastest SQL-like
TypeORM Decent Auto OK ActiveRecord/DataMapper
Sequelize Weak Auto OK Legacy
Kysely Excellent Manual Fast SQL builder

常见问题 FAQ

Q: Prisma vs Drizzle? A: Prisma 抽象更高(Schema DSL,自动迁移),开发体验好;Drizzle 更接近 SQL、bundle 更小、边缘运行时更快。

Q: 冷启动慢? A: Prisma 5+ 提供 driverAdapters,去掉 Rust 引擎,冷启动大幅改善。

Q: 能写原生 SQL 吗? A: 能。prisma.$queryRaw$executeRaw 支持模板字符串参数化查询。

来源与致谢 Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets