DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Do you use ORM? What about native SQL features?

I think there are scenarios here.

  • What if you are married to a dialect?
  • What if you want it flexible?

Top comments (13)

Collapse
 
maksimepikhin profile image
Maksim N Epikhin (PIKHTA)

We used this on the example of large projects. It is convenient to use, but there are serious problems with memory and query speed. So, for example, in yii2, exporting data to csv format when using activerecord models gave out timeout or allowed memory ... While pure SQL solved the problem 100%. From my own experience, I can say that for small projects orm and activerecord are very good tools, but for large projects it is already necessary to deal with serious optimization.

Collapse
 
vbilopav profile image
vbilopav

What if you are married to ORM library?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Which library, which language, in your case?

Collapse
 
vbilopav profile image
vbilopav

Any library, any language.

The library might lose support, you might need to upgrade to a higher version with breaking changes.

Or perhaps you want to use some of the functionalities in different services with different languages or even reimplement the backend layer in a different language.

Those things are extremely hard if not even impossible when using ORM.

Collapse
 
drhyde profile image
David Cantrell

So pick the right ORM, one that is flexible, and which lets you feed it (parts of) SQL queries when necessary.

Collapse
 
dabjazz profile image
Yash_Jaiswal

I prefer raw sql queries but then it increases the risk of SQL injection

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I think ORM does translate to SQL queries, except that it isn't maintained by you.

Collapse
 
dabjazz profile image
Yash_Jaiswal

Yes, but the execution of raw sql queries are faster.

Collapse
 
rsvp profile image
Аqua 🜉іtæ ℠

What about native NoSQL for a small projects? I mean how fast would it be with MongoDB & GraphQL. How many of those pairs u're able to setup simultaneously?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

You can do what you want, but the real strength of MongoDB lies in Aggregation framework.

Otherwise, it doesn't even matter which database you choose.

Collapse
 
rsvp profile image
Аqua 🜉іtæ ℠

Well. The only thing do DATA-base stand 4 - the data. I mean types, memory allocation, responsiveness, etc. Any frameworks is stand for frame. So, no any relations. But my point was about GraphQL as ORM replacement. If it possible to say so. Just an analogy.

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

The way I usually use ORM is to attach Properties / Methods to Objects (in Object * Model).

GraphQL goes by a different paradigm.

Collapse
 
matluz profile image
Matheus Luz

I was in the SQL query gang until I saw this video: youtu.be/ya1fwxnmlQs