Skip to content
BENIBIX Learn

Object-Relational Mapping (ORM)

Development🗃️ DatabasesDatabases in Code

Also known as ORM, Object Relational Mapper

Code that lets you use rows as objects in your own language. You write no SQL.

Think of it like

Think of it like a helper who speaks two tongues. You talk in yours, and it talks to the database in its own.

Example

Emma's Python app uses an ORM. She writes Customer(name="Lucy") and the ORM sends the INSERT for her.

Why it matters

Most web frameworks come with an ORM. It is how many coders talk to a database each day.

Definition

An ORM is a library that lets you work with rows as objects in your own code. Instead of writing SQL, you write code like user.save() or Order.find(5). The ORM turns that into SQL, runs it and turns the rows back into objects. It saves typing and catches some mistakes early. But it can hide slow queries, so it helps to know the SQL it writes.

Common mistake

Never looking at the SQL the ORM sends. A loop that looks harmless can send hundreds of queries.

Key takeaways

  1. 1
    Rows as objects. Use your own language, not SQL.
  2. 2
    SQL written for you. The ORM builds and runs it.
  3. 3
    Check what it sends. It can hide slow queries.