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:

ConceptDescriptionBuilding block in traditional ORMsBuilding block in Prisma ORMSource of truth in Prisma ORM
Object schemaThe in-memory data structures in your applicationsModel classesGenerated TypeScript typesModels in the Prisma schema
Data MapperThe code which transforms between the object schema and the databaseMapper classesGenerated functions in Prisma Client@map attributes in the Prisma schema
Database schemaThe structure of data in the database, e.g., tables and columnsSQL written by hand or with a programmatic APISQL generated by Prisma MigratePrisma 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.

Reference

Is Prisma ORM an ORM? | What is an ORM? | Prisma Docs