An ORM (Object-Relational Mapping) is a tool that bridges an application's object-oriented code and a relational database, so data can be handled as objects without writing every SQL query by hand.
In practice, a customers table becomes a Customer class in the code. To save a customer, the developer creates an object and the ORM generates the matching SQL query. It also handles relationships between tables, schema changes (migrations), and protects against some vulnerabilities such as SQL injection.
Each ecosystem has its own:
- PHP: Doctrine (Symfony), Eloquent (Laravel)
- Java: Hibernate
- Python: SQLAlchemy, the Django ORM
- JavaScript / TypeScript: Prisma, TypeORM
An ORM saves a lot of time, but hides what happens in the database. Misused, it generates inefficient queries, such as the so-called N+1 problem, where a simple list triggers hundreds of queries.
