TIL – It’s more clear Data Mapper – Active Record, ORM?

Active Record is a design pattern where the model is responsible for both the data and the behavior related to that data, allowing direct interaction with the database through the model itself. In contrast, the Data Mapper pattern separates the in-memory objects from the database, using a repository to manage data access, which is more suitable for larger applications. There is a pretty good explanation here https://typeorm.io/active-record-data-mapper/

Some examples regarding these patterns:

ORM (Object-Relational Mapping) is a programming technique that enables developers to interact with relational databases using high-level object-oriented programming languages, abstracting the complexities of SQL. By mapping database tables to programming objects, ORM allows for seamless data manipulation through objects rather than cumbersome queries. This approach enhances productivity, increases code readability, and helps prevent security issues like SQL injection. The “Patterns of Enterprise Application Architecture” book by Martin Folwer is a good source for this.

Leave a comment