What is Object Relational Mapping?

svg viewer

What is ORM?

Object Relational Mapping (ORM) is the bridge between databases and object-oriented programming. The ORM equips you with object-oriented tools to run commands that you would usually run on databases. It masks out the complicated intricacies of the databases and lets you manipulate them with your choice of programming language (must support object-oriented programming).

Pros

  • It is easier to query using ORM than MySQL.
  • Hides the complex processes under-the-hood and only lets you worry about the high-level implementation.
  • There is no need to change the code if the underlying database changes.

Cons

  • Learning an ORM from scratch is time-consuming.
  • You cannot directly dive into an ORM without learning MySQL. Even though the ORM helps you abstract the complex details, it is pertinent to know the consequence of each command under-the-hood.
  • You may run into performance issues while coding complex queries using an ORM.

Example

There is a wide range of ORMs in different object-oriented programing languages. Let’s consider the following MySQL query:

$value = SELECT * FROM collection WHERE day = 'Monday' 

The above query retrieves a value from the table collection in which columns (day) are equal to Monday.

In an ORM, this query would look something like this:

value = collection.query(day = 'Monday')

Here is a list of ORM libraries in different object-oriented programming languages.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved