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 9 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
Concorrenti
- TypeORM, Sequelize — ORM Node storici con pattern Active Record / Data Mapper
- Mikro-ORM — Data Mapper alternativa
Nel contesto italiano
Prisma sta entrando nei team Node.js italiani TypeScript-first: startup fintech/SaaS/AI, team che migrano da Sequelize/TypeORM, progetti Next.js fullstack.
Riferimenti: Prisma 2.0 (9 giugno 2020). Prisma Labs, Berlin. Søren Bramer Schmidt, Johannes Schickling. Licenza Apache 2.0. Schema DSL, Client, Migrate, Studio. Multi-DB.
