ORM

natasha selvidge
2 min readAug 30, 2021

--

ORM stands for Object-Relational Mapping and it is a programming technique that abstracts your code from the database behind it. When we work with an object-oriented system, there is mismatch between the object model and the relational database. RDBMSs represent data in a tabular format whereas object-oriented languages represent it as an interconnected graph of objects.

Simply put, if you’re building an application using an ORM library and your application speaks with PostgreSQL, you could switch to MariaDB at anytime without changing your code. You would only need to change data source configuration.

Let’s break this down with an example. Suppose you want to create a notes application. You would create a Note class in your back end and you would have a notes table in your database. So now you want to display all the notes to the UI you’re building along the way.

How would you retrieve all the data?

Sure, you could write all that boilerplate code by yourself. You would write and execute an SQL query and get the result. Then, you would traverse an array until there are no rows left and each row you would map to a Note instance. You have to ask yourself. Is this the process I repeat in most of my projects? It is. ORM libraries do all this work instead of you in a way that is completely transparent. In other words, with ORM, you never write queries to the database in your code. Instead, you only interact with objects of specific classes that represent records in the database.

There are alot of ORM libraries out there. Some of them are Hibernate (for Java), Propel (for PHP), Sequelize (for JavaScript), SQLALchemy (for Python), Nhibernate (for C#) etc. Some frameworks have an internal ORM such as Django and Odoo.

--

--