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.
Like it?React
🧵

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

May 24, '23 18:53

What are joins in Ruby on Rails and how does it work?

What is an RDBMS (relational database management system)?
Sep 21, '24 08:56

What is an RDBMS (relational database management system)?

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

What is DDL (Data Definition Language) and DML (Data Manipulation Language)? When and for what purposes are they used?
Mar 27, '24 18:37

What is DDL (Data Definition Language) and DML (Data Manipulation Language)? When and for what purposes are they used?

What is XOR and how does it work?
Mar 21, '25 17:05

What is XOR and how does it work?

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

Main methods of authentication in API
Oct 19, '25 20:26

Main methods of authentication in API

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

What is ivar in Ruby / Rails?

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

MCP: a new internet where websites communicate with AI

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?

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

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

What is NP-complexity?

May 31, '26 23:56

Copilot error - client not supported: bad request: the specified API version is no longer supported.

Elasticsearch, OpenSearch, and alternatives: a complete overview
Jul 5, '26 10:36

Elasticsearch, OpenSearch, and alternatives: a complete overview

Jul 10, '26 11:35

How to quickly reset the QA/Staging branch to the state of main