The astonishing tail of ORM’s

Sanjana Maheshwari
2 min readJul 9, 2021

--

I have been working on Django and Django Rest Framework from quite some time now. It really excites me the way python makes it simpler for folks like to me to understand web in a simplified manner :P
I came across ORM’s i.e. Object Relation Mappers quite a lot during my journey. I remember being asked about them in one of my interviews and being fully blank, just like that :P I recently realised about the super powers of ORM. The following blog discusses same. Stay with me :D

What is ORM ?

It is a code library that automates the transfer of data stored in relational databases into objects that are commonly used in application programming.

That’s fine ? But how are they helping me as a developer ?

While making models for django projects, we define tables of relational database as python classes. They are actually helping us to write python code instead of SQL for CRUD operations ! This ability to write python code instead of long struggling SQL queries can actually speed the process of building applications. Believe me I have felt this recently! While some developers may not find switching between languages during prototype phase an annoying task , but it actually slows down the process of building applications.ORMs also make it theoretically possible to switch an application between various relational databases. For example, a developer could use SQLite for local development and MySQL in production. A production application could be switched from MySQL to PostgreSQL with minimal code modifications.

Here are some ORM’s implementations written in python -

  • Sqlalchemy
  • Peewee
  • The Django ORM

Are there any downsides of using ORM’s ?

Impedance mismatch, reduced performance and shifting complexity from database to application code are some common ones.

Fun Fact :

There is a lot of hand waving “may or may not" or “potential for" with ORM’s. In some minor cases there can be great improvements by having a person who is fluent in SQL and can write tuned SQL commands to replace ORM generated SQL code. It may be the case , that this will lead us to a better performance.

--

--