Glossary · Databases

ORM (Object-Relational Mapping)

An ORM is a library that maps database tables to objects in a programming language, so code can query and save data without writing raw SQL.

Updated October 6, 2026

An Object-Relational Mapper (ORM) is a library that maps database tables and rows to classes and objects in a programming language. You read and write data through objects, and the ORM generates the SQL.

Why it matters

ORMs speed up development, keep schema definitions near the code, and help guard against SQL injection through parameterized queries. They can also hide what the database is doing, leading to slow or excessive queries, such as the N+1 pattern. Good teams use an ORM for routine work and drop to raw SQL for complex reports.

Example

# Typical ORM style (pseudo-code)
user = User.objects.get(id=7)
user.name = "Asha"
user.save()

Behind the scenes the ORM issues SELECT ... WHERE id = 7 and then UPDATE users SET name = ... WHERE id = 7.

Common mistakes

  • Never looking at the SQL the ORM generates, so inefficient queries go unnoticed.
  • Loading related objects in a loop, creating N+1 queries.
  • Assuming the ORM removes the need to understand indexes and transactions.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.