ORM Node.js: un vuoto
L’ecosistema Node ha storicamente avuto ORM problematici:
- Sequelize — pattern Active Record, TypeScript spesso “aggiunto dopo”
- TypeORM — decoratori, bug noti, manutenzione lenta
- Mikro-ORM, Objection.js, Knex — nicchia
Serve un approccio schema-first, type-safe, DX-moderna.
Il rilascio
Prisma 2.0 è rilasciato da Prisma Labs (Berlin) il 23 giugno 2020. Licenza Apache 2.0. Founder: Søren Bramer Schmidt, Johannes Schickling. Versione 1.x era GraphQL-focused; la 2.0 pivota a ORM general purpose.
Architettura
- Schema DSL (
schema.prisma) — definizione dichiarativa di model, field, relazioni - Prisma Client — TypeScript client generato da schema
- Prisma Migrate — migrations basate su schema diff
- Prisma Studio — GUI per browsing DB
model User {
id Int @id @default(autoincrement())
email String @unique
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
const users = await prisma.user.findMany({
where: { email: { endsWith: '@example.com' } },
include: { posts: true }
});
// users is typed: User & { posts: Post[] }[]
Caratteristiche
- Type safety end-to-end — tipi generati da schema, zero manual typing
- Query builder fluent — no raw SQL (anche se supportato con
$queryRaw) - Migrations dichiarative
- Auto-complete completo in IDE
- Nested writes — crea record correlati in una call
- Introspection — genera schema da DB esistente (
prisma db pull) - Seed data
- Multi-DB: PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, CockroachDB
Prisma Accelerate & Pulse
Prodotti commerciali Prisma:
- Accelerate — connection pooling e cache globale (Edge-compatibile)
- Pulse — change data capture real-time
- Prisma Data Platform — console cloud
Versioni
- 2.0 (giugno 2020) — prima stabile ORM
- 3.0 (settembre 2021) — referential actions, PlanetScale support
- 4.0 (giugno 2022) — Node 14+, MongoDB GA
- 5.0 (luglio 2023) — Node 16+, performance boost
- 6.0 (novembre 2024) — Node 18+, Rust → TypeScript query engine migration
Concorrenti
- Drizzle ORM (2022+) — TypeScript SQL-like, zero-abstraction, Edge-friendly — in forte crescita
- Kysely — type-safe query builder, niente schema
- TypeORM, Sequelize — legacy
- Mikro-ORM — Data Mapper alternativa
Nel contesto italiano
Prisma è molto adottato in:
- Startup italiane TypeScript-first (fintech, SaaS, AI)
- Team Node che migrano da Sequelize/TypeORM
- NestJS projects (via
@nestjs/prismawrappers community) - Next.js fullstack app
- Edge runtime (Cloudflare Workers) con Accelerate
Molti bootcamp TypeScript italiani insegnano Prisma come ORM di default nel 2024-2026.
Riferimenti: Prisma 2.0 (23 giugno 2020). Prisma Labs, Berlin. Søren Bramer Schmidt, Johannes Schickling. Licenza Apache 2.0. Schema DSL, Client, Migrate, Studio. Multi-DB. Versione corrente 6.x (2024).
