What is ORM? Why to use it and Brief Introduction of ORM Frameworks.

Vinayak Grover
3 min readNov 8, 2019

--

Hi, this article is to explain the Object Relational Mapping(ORM) and Why to use it, with the brief introduction about some ORM frameworks and by the end of this article you will get brief knowledge of ORM.

What is an ORM?

Before getting into the proper definition of ORM, first let me take an example which will explain the term in a more better way. So, have you ever used SQL database in your application and have you ever used SQL queries to update, insert or retrieve the data, no matter how tough the queries are. So, here comes the idea of Object Relational Mapping(ORM). And it is a programming technique for converting data between incompatible type systems using object-oriented programming languages.

It means you can write database queries using the object oriented paradigm of your preferred language and there are many free and commercial packages available that perform object relational mapping.

ORM sets the mapping between the set of objects which are written in the preferred programming language like JavaScript and relational database like SQL. It hides and encapsulates the SQL queries into objects and instead of SQL queries we can use directly the objects to implement the SQL query.

Why to use ORM and What are the benefits of ORM?

Now the question arises that if we can use directly the queries then why to include the ORM frameworks in between.

So, first of all you get to write in the language you are already using. It is sometime tough to write SQL queries directly as they are complicated in some cases. So, to maintain the fluency we use ORM, so that we can write in the language we know.

Second, it hides the SQL or any other database query away from your application logic.

Third, for heavy database usage like creating 10+ tables and using many queries in them, then it is good to use ORM as it reduce the code and give better understanding of the code to you and as well as to your team mates and it makes your application faster and easier to maintain.

What are some commonly used ORM Frameworks?

There are many different ORM frameworks that can be used with different languages like Enterprise Java Beans(EJB), Hibernate, etc. can be used with Java.

And with JavaScript we can use bookshelf.js which is built on Knex SQL Query Builder. It is designed to work with PostgreSQL, MySQL and SQLite3. And the other framework used with JavaScript is mongoose.js which is designed to work with MongoDB.

So, lets conclude the article in a very simple line that, ORM is used to write Database queries in the preferred languages instead of writing the Raw Database queries.

--

--