Skip to main content
Web DevDatabases & CachingDiagramBeginner

ORM (Object-Relational Mapping)

KO: ORM (객체-관계 매핑)·EN: ORM (Object-Relational Mapping)·JA: ORM(オブジェクト関係マッピング)·Object-Relational Mapping

A programming layer that maps relational database tables and rows to application objects and types, providing type-safe CRUD, relations, and migrations

Table of Contents

Structure Diagram

Application Entity ↔ ORM Mapper ↔ Parameterized SQL FlowTap a node
Typed APIQuery GenDDL SyncTyped Ent…ORM (Pris…Parameter…Schema Mi…
ROOTTyped Entity / Model
1 link
Quick Answer

What is ORM (Object-Relational Mapping)?

A programming layer that maps relational database tables and rows to application objects and types, providing type-safe CRUD, relations, and migrations. It is a core concept in Databases & Caching within Web Dev.

Core Principles

Application code models data as typed objects and nested graphs, while relational databases store normalized tables and foreign keys. An ORM (Object-Relational Mapper) bridges this impedance mismatch by translating typed model operations into SQL queries and mapping result rows back into objects.

Beyond reducing boilerplate CRUD code, modern ORMs provide compile-time type safety, versioned schema migrations, and parameterized queries by default to guard against SQL injection.

Practical Takeaways

  • Inspect the generated SQL: ORM convenience can hide N+1 loops, wide SELECT * fetches, and suboptimal joins. Keep SQL logging enabled in dev and profile critical paths with EXPLAIN ANALYZE.
  • Use escape hatches for complex analytics: Don't fight the ORM for recursive CTEs, window functions, or heavy reporting—drop down to raw SQL or a typed query builder (Drizzle, Kysely) where SQL shines.
  • Review migration DDL before production: Always inspect auto-generated migration files so table-locking ALTER statements don't cause downtime.

Notable Examples

  • Prisma & Drizzle ORM (TypeScript): End-to-end type safety from database schema to API responses.
  • JPA/Hibernate, SQLAlchemy, Django ORM: Mature persistence layers powering enterprise backends.