# Data mapper pattern

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Data_mapper_pattern
> Markdown URL: https://mediated.wiki/source/Data_mapper_pattern.md
> Source: https://en.wikipedia.org/wiki/Data_mapper_pattern
> Source revision: 1281231142
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

In [software engineering](/source/Software_engineering), the **data mapper pattern** is an [architectural pattern](/source/Architectural_pattern_(computer_science)). It was named by [Martin Fowler](/source/Martin_Fowler_(software_engineer)) in his 2003 book *Patterns of Enterprise Application Architecture*.[1] 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](/source/Data_access_layer) that performs bidirectional transfer of data between a persistent data store (often a [relational database](/source/Relational_database)) 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.[2] The layer is composed of one or more mappers (or [Data Access Objects](/source/Data_Access_Object)), 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](/source/Software_framework) for many programming environments.

### Java/.NET

- [MyBatis](/source/MyBatis) persistence framework
- [Hibernate](/source/Hibernate_(framework)) ([NHibernate](/source/NHibernate)) persistence framework

### Node.js / TypeScript

- [Bookshelf.js](http://bookshelfjs.org/) library
- [TypeORM](https://typeorm.github.io/) library
- [Massive.js](https://massivejs.org/) library
- [Prisma](https://www.prisma.io/)
- [Objection.js](https://vincit.github.io/objection.js/) library
- [MikroORM](https://mikro-orm.io/) library
- [LDkit](https://ldkit.io/) Object Graph Mapper (OGM) for RDF data sources

### PHP

- [Atlas](https://github.com/atlasphp/Atlas.Orm) ORM (data mapper, table data gateway, query builder, and PDO wrapper)[3]
- [Doctrine2](/source/Doctrine_(PHP)) Object Relational Mapper (ORM) and the Database Abstraction Layer[4]
- [Cycle](https://github.com/cycle/orm) ORM (PHP DataMapper ORM and Data Modelling Engine)[5]
- [CakePHP](https://github.com/cakephp/orm) ORM (PHP DataMapper ORM, query builder, and PDO wrapper)

### Perl

- [DBIx](https://metacpan.org/dist/DBIx-Class)[6]

### Python

- [SQLAlchemy](/source/SQLAlchemy) library
- [mincePy](https://mincepy.readthedocs.io/en/latest/) library

### Ruby

- [DataMapper](http://datamapper.org/) library (Actually this library implemented the Active Record design pattern, its successor, DataMapper 2 (now [ROM](http://rom-rb.org/)) aimed to actually implement the design pattern it was named after)

### Elixir

- [Ecto](https://github.com/elixir-ecto/ecto) persistence framework

## References

1. Fowler, Martin (2003). [*Patterns of enterprise application architecture*](https://books.google.com/books?id=FyWZt5DdvFkC&dq=active+record&pg=PT187). Addison-Wesley. ISBN 978-0-321-12742-6.

1. ["What's the difference between Active Record and Data Mapper?"](https://www.culttt.com/2014/06/18/whats-difference-active-record-data-mapper)

1. ["Atlas ORM – Atlas"](http://atlasphp.io/)

1. ["Doctrine2 and ActiveRecord – Doctrine2"](https://web.archive.org/web/20130721044554/http://www.doctrine-project.org/blog/your-own-orm-doctrine2.html#doctrine2-and-activerecord). [Doctrine2](/source/Doctrine_(PHP)). Archived from [the original](http://www.doctrine-project.org/blog/your-own-orm-doctrine2.html#doctrine2-and-activerecord) on 2013-07-21. Retrieved 2013-04-02.

1. ["Cycle ORM – Cycle"](https://github.com/cycle/orm). *[GitHub](/source/GitHub)*

1. ["stack overflow – DBIx"](https://stackoverflow.com/questions/281440/is-there-an-orm-for-perl)

---
Adapted from the Wikipedia article [Data mapper pattern](https://en.wikipedia.org/wiki/Data_mapper_pattern) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Data_mapper_pattern?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
