DEV Community

Cover image for What is an ORM
Freweini Beyene
Freweini Beyene

Posted on

What is an ORM

An ORM (Object Relational Mapper), is a piece of software designed to translate between the data representations used by databases and those used in object-oriented programming.
ORM is the layer that connects object-oriented programming (OOP) to relational databases. To perform different operations like creating, reading, updating, and deleting data from a database we use SQL for performing these operations in relational databases. ORM as a tool can help simplify the interaction between the relational databases and different OOP languages that you might be using.

The idea of ORM is based on abstraction. it creates a logical model of the program with a high level of abstraction, i.e., without specifying the underlying code details. The ORM mechanism makes it possible to address, access and manipulate objects without having to consider how those objects relate to their data sources.

Developers can also perform various data-creating, reading, updating, and deleting (CRUD) operations in relational databases without using SQL. This capability is particularly useful for developers who either don't know SQL or don't want to waste time writing SQL code. It's recommended for developers to know SQL queries since behind the hood the operation remains the same old SQL queries are being executed.

to see how ORM is simplifying the SQL let's take as an example

SQL:

SELECT name, email, phone_no FROM users WHERE id= 12
this query will return the name, email, phone_no from a table called users where users id of 12

the same query can be written in ORM tool as

users.GetById(12)
So the code above does the same as the SQL query.

Depending on the languages you are using you can find different compatible ORM tools: for example

TypeORM: is an ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, and WebSQL databases.

Sequelize: is a modern TypeScript and Node.js ORM for Oracle, Postgres, MySQL, MariaDB, SQLite and SQL Server, and more.

Depending on the language you are planning to use you can find an ORM that will work for you.

Thanks for reading.

Top comments (0)