data mapper pattern

{{Short description|Architectural pattern in software engineering}}

In software engineering, the data mapper pattern is an architectural pattern. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture.{{cite book |last=Fowler |first=Martin |title=Patterns of enterprise application architecture |publisher=Addison-Wesley |year=2003 |isbn=978-0-321-12742-6 |url=https://books.google.com/books?id=FyWZt5DdvFkC&dq=active+record&pg=PT187 }} 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) 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.{{Cite web|title=What's the difference between Active Record and Data Mapper?|url=https://www.culttt.com/2014/06/18/whats-difference-active-record-data-mapper}} 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 =

= Node.js / TypeScript =

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

= PHP =

  • [https://github.com/atlasphp/Atlas.Orm Atlas] ORM (data mapper, table data gateway, query builder, and PDO wrapper){{cite web|url=http://atlasphp.io/|title=Atlas ORM{{spaced ndash |archiveurl=http://atlasphp.io}} Atlas}}
  • Doctrine2 Object Relational Mapper (ORM) and the Database Abstraction Layer{{cite web|url=http://www.doctrine-project.org/blog/your-own-orm-doctrine2.html#doctrine2-and-activerecord|title=Doctrine2 and ActiveRecord{{spaced ndash }} Doctrine2|publisher=Doctrine2|access-date=2013-04-02|archive-url=https://web.archive.org/web/20130721044554/http://www.doctrine-project.org/blog/your-own-orm-doctrine2.html#doctrine2-and-activerecord|archive-date=2013-07-21|url-status=dead}}
  • [https://github.com/cycle/orm Cycle] ORM (PHP DataMapper ORM and Data Modelling Engine){{cite web|url=https://github.com/cycle/orm|title=Cycle ORM{{spaced ndash }} Cycle|website=GitHub}}
  • [https://github.com/cakephp/orm CakePHP] ORM (PHP DataMapper ORM, query builder, and PDO wrapper)

= Perl =

  • [https://metacpan.org/dist/DBIx-Class DBIx]{{cite web|url=https://stackoverflow.com/questions/281440/is-there-an-orm-for-perl|title=stack overflow{{spaced ndash |archiveurl=https://stackoverflow.com/questions/281440/is-there-an-orm-for-perl}} DBIx}}

= Python =

  • SQLAlchemy library
  • [https://mincepy.readthedocs.io/en/latest/ mincePy] library

= Ruby =

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

= Elixir =

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

See also

  • {{annotated link|Active record pattern}}
  • {{annotated link|Object-relational mapping}}

References