Photo by rawpixel on UnsplashAs a relative newcomer to the programming world, terms like Object-Relational-Mapper can sound really intimidating. The nice part about ORMs, is that they actually make it easier to write code once you get the hang of them (usually).
Đang xem: Object relational mapping là gì
In this post, I aim to explain what an ORM does, as well as the pros and cons of using them in your projects.
Let’s get to it!
What is an ORM?
Before we talk about what an Object-Relational-Mapper is, it might be better to talk about Object-Relational-Mapping as a concept first.
Unless you’ve worked exclusively with NoSQL databases, you’ve likely written your fair share of SQL queries. They usually look something like this:
SELECT * FROM users WHERE email = 'test
test.com';Object-relational-mapping is the idea of being able to write queries like the one above, as well as much more complicated ones, using the object-oriented paradigm of your preferred programming language.
Xem thêm: lq mobile
Long story short, we are trying to interact with our database using our language of choice instead of SQL.
Here’s where the Object-relational-mapper comes in. When most people say “ORM” they are referring to a library that implements this technique. For example, the above query would now look something like this:
As with any technique, there are tradeoffs that should be considered when using an ORM.
Let’s take a look at some of the pros and cons!
Tip: Use Bit to organize your components and make them discoverable for your team, to build new applications faster. It’s open-source, give it a try.
What are some pros of using an ORM?