In
software engineering, the data mapper pattern is an
architectural pattern
An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context. The architectural patterns address various issues in software engineering, such as computer hardware perform ...
. It was named by
Martin Fowler in his 2003 book ''Patterns of Enterprise Application Architecture''. The interface of an object conforming to this pattern would include functions such as Create, Read, Update, and Delete, that operate on objects that represent domain entity types in a data store.
A Data Mapper is a
Data Access Layer that performs bidirectional transfer of data between a persistent data store (often a
relational database
A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
) and an in-memory data representation (the domain layer). The goal of the pattern is to keep the in-memory representation and the persistent data store independent of each other and the data mapper itself. This is useful when one needs to model and enforce strict business processes on the data in the domain layer that do not map neatly to the persistent data store.
The layer is composed of one or more mappers (or
Data Access Objects), performing the data transfer. Mapper implementations vary in scope. Generic mappers will handle many different domain entity types, dedicated mappers will handle one or a few.
Implementations
Implementations of the concept can be found in various
frameworks for many programming environments.
Java/.NET
*
MyBatis persistence framework
*
Hibernate
Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
(
NHibernate) persistence framework
Node.js / TypeScript
Bookshelf.jslibrary
TypeORMlibrary
Massive.jslibrary
PrismaObjection.jslibrary
MikroORMlibrary
PHP
*
Atlas ORM (data mapper, table data gateway, query builder, and PDO wrapper)
*
Doctrine2 Object Relational Mapper (ORM) and the Database Abstraction Layer
CycleORM (PHP DataMapper ORM and Data Modelling Engine)
Python
*
SQLAlchemy library
mincePylibrary
Ruby
DataMapper library (Actually this library implemented the Active Record design pattern, its successor, DataMapper 2 (no
ROM aimed to actually implement the design pattern it was named after)
Elixir
Ectopersistence framework
See also
*
*
References
{{DEFAULTSORT:Data mapper pattern
Software design patterns
Architectural pattern (computer science)