Object / relational mapping (sometimes abbreviated as O / R mapping or ORM) is the connection of rich objects in an application to a relational database (RDBMS) table. With ORM, you can save and read object attributes and relationships in your application from the database by writing a small amount of access code instead of writing SQL statements directly. Rails Guide
In short, if you want to get ʻusers` information when using SQL,
SELECT * FROM users ;
You should get all the records with, but if you use O / R mapping
user.all
Like, in rails, thanks to ActiveRecord, it is possible to get all the contents of users without writing SQL.
I often use it
.find_by(name: 'TARO')
Methods like
SELECT * FROM users WHERE name = "TARO";
You will get the same result as SQL like this.
As mentioned above, it is possible to reduce the work of complicated database operations such as the processing that originally wrote SQL.
While it has the advantage of being convenient, it also has some disadvantages.
There are other disadvantages such as not being able to use the functions of a specific DB, but there are also advantages such as being able to search data intuitively and not having to modify the source code when changing the database.
Since I was studying with almost no study of SQL myself, there were many situations where knowledge of SQL was required when proceeding with development with java and kotlin in business, and at first I was confused at all.
Recently, it is often installed as standard in web frameworks, and it is necessary to know the syntax for each language, but I would like to actively use the O / R mapper as long as it can be supported. I have.
https://qiita.com/gomiryo/items/6d448c500749f91242d2 https://railsguides.jp/active_record_basics.html
Recommended Posts