DEV Community

Hrn Svncハルン
Hrn Svncハルン

Posted on

Should i use an ORM? When to use it? Which one?

Hey everyone,

i am currently working on a private project to get my nodejs skills a bit developed. I am trying to create an api with express and use a postgres db to store data. Nothing fancy here, just creating some users and stuff.
My question is: Should i use an ORM? Sure for that small case queries will do the work for me but what about more complex projects with bigger sets of data? I don't want to start a discussion or something just get a hint.

Thanks a lot

Top comments (2)

Collapse
 
jmfayard profile image
Jean-Michel 🕵🏻‍♂️ Fayard • Edited

I don't no a thing about nodejs, but here would be my framework to answer this question:

  • Do you have short term goals?
  • Is there one NodeJS CRM that is way more popular than all the others?

If you answer yes to those two questions, do use that CRM, you will get started faster.

If not, I would go for SQL, because knowing one CRM is fine, but after switching to 5-10 different CRMs, you start to wonder whether your time would not have been better invested into learning SQL, the lingua franca of relational database.

My favorite approach in the Kotlin world, is to embrace SQL but make it typesafe

github.com/cashapp/sqldelight
github.com/JetBrains/Exposed

Collapse
 
rolfstreefkerk profile image
Rolf Streefkerk

An ORM always has trade offs between performance (you're loading in extra libraries and at run time it needs to translate model to query) and convenience.

The other think is around tooling support, Sequelize is I think the biggest ORM for Node, takes care of a lot of the connectivity with databases and basic querying.

Then there are tools around data validation with JSON Schema that can be integrated with Sequalize that further remove the need to program this yourself.

In the end, there's a lot of benefit using this tooling to speed up development with relatively little down side.

If you want to learn the nitty gritty details on how it actually works, I would say do not use an ORM but write everything yourself with the basic Postgres API, it's a good learning experience.

Then for larger projects it probably makes sense to start using tooling to automate / generate code that is then considered to be boiler plate (you know how it works). Even with an ORM, you can always run custom queries against the database if you need to.

I hope that helps