All original content is created in Ukrainian. Not all content has been translated yet. Some posts may only be available in Ukrainian.Learn more

What is ORM and why is it needed?

Post cover: What is ORM and why is it needed?
This content has been automatically translated from Ukrainian.
When we work with databases, we usually have to write SQL queries - selections, inserts, updates, etc. But as the project grows, these queries can number in the hundreds, and maintaining them becomes difficult.
This is where ORM (Object-Relational Mapping) comes into play - a technology that allows you to work with the database through objects of the programming language.
ORM “translates” data from tables in the database into objects that can be worked with in code.
For example, instead of writing:
SELECT * FROM users WHERE id = 1;
in Ruby on Rails we simply do:
user = User.find(1)
and get a User object that has methods, properties, and behavior like a regular Ruby class.
Advantages of ORM
  • Minimum SQL - most queries are generated automatically.
  • Fewer errors - ORM checks types, relationships, validations.
  • Faster development - CRUD operations (create, read, update, delete) are written in a few lines.
  • Portability - easy to change the DBMS (for example, from PostgreSQL to MySQL) without rewriting queries.
  • Convenient handling of relationships - has_many, belongs_to, has_one, etc.
Disadvantages of ORM
  • Performance - sometimes ORM generates “heavy” queries that need to be optimized manually.
  • Black box - difficult to understand what happens under the hood.
  • Not for everything - complex SQL queries or analytical selections are better written manually.
Examples of ORM
  • Ruby - ActiveRecord
  • Python - SQLAlchemy, Django ORM
  • JavaScript - Sequelize, Prisma
  • PHP - Eloquent (Laravel)
In short. ORM is a bridge between the world of objects and tables. It allows developers to think less about SQL and more about business logic. But like any tool, ORM is worth understanding to avoid turning convenience into a performance trap.

This post doesn't have any additions from the author yet.

What is NP-complexity?
Sep 16, '25 19:31

What is NP-complexity?

meme code
meme code@memecode
Offset vs Cursor Pagination in Rails: what to choose and why
Sep 24, '25 15:22

Offset vs Cursor Pagination in Rails: what to choose and why

meme code
meme code@memecode
What is Row Security in PostgreSQL and why is it important for Rails developers
Oct 4, '25 19:06

What is Row Security in PostgreSQL and why is it important for Rails developers

meme code
meme code@memecode
What is ivar in Ruby / Rails?
Oct 19, '25 20:12

What is ivar in Ruby / Rails?

meme code
meme code@memecode
Main methods of authentication in API
Oct 19, '25 20:26

Main methods of authentication in API

meme code
meme code@memecode
What are the differences between OAuth 1 and OAuth 2
Oct 19, '25 20:34

What are the differences between OAuth 1 and OAuth 2

meme code
meme code@memecode
MCP: a new internet where websites communicate with AI
Nov 4, '25 11:43

MCP: a new internet where websites communicate with AI

meme code
meme code@memecode
Why is TOON better than JSON when working with AI?
Nov 14, '25 15:14

Why is TOON better than JSON when working with AI?

meme code
meme code@memecode