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 queries —
includeandselectfor 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.jsKey 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
- Docs: https://www.prisma.io/docs
- GitHub: https://github.com/prisma/prisma
- License: Apache 2.0