ORM wrap around the relational database system (RDBMS) and create a virtual object-oriented database that is used within and from the programming language.
Basically, ORM defines a mapping between your classes and database tables or class members and table columns and the ORM manage the communication between your codes and the underlying database. ORM framework wrap relation database tables into the classes of programming language, so that instead of writing SQL queries to manipulate the database, we can use methods and objects.
Form
Now question is that why I use ORM frameworks? What are advantages of ORM? So, here is your answer
Advantages of using ORM frameworks
- ORM framework protects your application against the SQL injection attacks. Hence the ORM frameworks filter and sanitize all data. So, you don’t need to worry about this.
- Since ORM handle all database related things like writing SQL statements, data type conversions etc. SO, it becomes easy in future if you want to change the database server of your application. Like your application currently use MySql and you need to use PostgreSQL as the database. It becomes very easy and needs very fewer efforts if you use an ORM. By the way, in my six years of experience, I saw this case only once.
- If you have more than 10 tables and more than 3 developers are working on an application. Then it is helpful to use ORM framework. Because ORM framework creates a consistent code style for your application. So, it becomes easy to work and the probability of messing up become less.
- There are lots of stuff are done automatically for you by ORM frameworks. For example database handling, table relations & joins, filtering data, I18N etc.
- It makes the maintenance work easy for you. Because ORM framework follows DRY practice. So, you have to write your data models only at one place. So, it becomes easy to maintain and update codes.
- A good ORM take care of synchronization of the data types between the programming language (Ex. PHP, Java) and the SQL database. So, it also handles the data type conversion related things for you.
- ORM supports to ACID properties and transactions (commit and rollback).
Disadvantages of using ORM frameworks
- You have to learn the ORM framework first. There is a learning curve in understanding and using ORM framework.
- ORM makes working easier. But unfortunately, developers skip learning SQL and database related things.
- Performance is fine for normal queries. But you can always do better with your own SQL queries.
- Sometime ORM fails to compete against native SQL queries in case of complex queries.