Prisma là ORM thế hệ mới với type-safety tuyệt vời, ngày càng được ưa dùng thay TypeORM. Schema định nghĩa trong prisma/schema.prisma với cú pháp riêng, prisma generate tạo Prisma Client type-safe hoàn toàn.
Setup NestJS: tạo PrismaService extends PrismaClient implements OnModuleInit, gọi this.$connect() trong onModuleInit(). Wrap trong @Global() @Module() để dùng toàn app. Prisma Client API rất fluent: prisma.user.findMany({ include, where, orderBy }), prisma.user.create({ data }), transactions với prisma.$transaction([]).
So sánh Prisma vs TypeORM: Prisma có type-safety tuyệt vời (auto-generated types từ schema), prisma migrate dev rõ ràng an toàn hơn synchronize: true của TypeORM. TypeORM quen thuộc với Java/Spring developers, hỗ trợ Active Record pattern. Prisma không hỗ trợ MongoDB aggregation pipeline tốt bằng Mongoose. Hiện tại Prisma được cộng đồng ưa chuộng hơn cho dự án mới.
Prisma is a next-generation ORM with excellent type-safety, increasingly preferred over TypeORM. The schema is defined in prisma/schema.prisma with its own syntax, and prisma generate creates a fully type-safe Prisma Client.
NestJS setup: create a PrismaService extending PrismaClient implementing OnModuleInit, calling this.$connect() in onModuleInit(). Wrap in a @Global() @Module() for app-wide use. Prisma Client API is fluent: prisma.user.findMany({ include, where, orderBy }), prisma.user.create({ data }), transactions with prisma.$transaction([]).
Prisma vs TypeORM: Prisma has excellent type-safety (auto-generated types from schema), prisma migrate dev is safer than TypeORM's synchronize: true. TypeORM is familiar to Java/Spring developers and supports Active Record pattern. Prisma handles MongoDB aggregation pipelines less well than Mongoose. Prisma is currently the community preference for new projects.