Prisma Advantage
How Prisma ORM implements the Data Mapper pattern
To understand how Prisma ORM’s implementation of the Data Mapper pattern differs conceptually to traditional Data Mapper ORMs, here’s a brief comparison of their concepts and building blocks:
| Concept | Description | Building block in traditional ORMs | Building block in Prisma ORM | Source of truth in Prisma ORM |
|---|---|---|---|---|
| Object schema | The in-memory data structures in your applications | Model classes | Generated TypeScript types | Models in the Prisma schema |
| Data Mapper | The code which transforms between the object schema and the database | Mapper classes | Generated functions in Prisma Client | @map attributes in the Prisma schema |
| Database schema | The structure of data in the database, e.g., tables and columns | SQL written by hand or with a programmatic API | SQL generated by Prisma Migrate | Prisma schema |
Prisma ORM aligns with the Data Mapper pattern with the following added benefits:
- Reducing the boilerplate of defining classes and mapping logic by generating a Prisma Client based on the Prisma schema.
- Eliminating the synchronization challenges between application objects and the database schema.
- Database migrations are a first-class citizen as they’re derived from the Prisma schema.