DEV Community

Discussion on: What NodeJS SQL Query Builder/ORM should I use for my Postgres DB, and why?

Collapse
 
dmfay profile image
Dian Fay

There are other O/R mappers besides Sequelize but it is still the biggest as far as I know.

Personally, the more I've worked with O/R mapping the more I've thought the entire approach is a mistake: object-relational impedance mismatch is very real and it always eventually hurts more than the toolkit helps. And in JavaScript especially, where we have anonymous objects, an expressive functional toolkit, and few compunctions about type safety, the Object side of things introduces a lot more overhead than I'm willing to countenance. There's no getting around writing models of some sort in a strongly-typed language like Java, but if you're using JavaScript it's just extra work.

I maintain a data mapper for Node and PostgreSQL: Massive.js. Focusing exclusively on Postgres lets us leverage its full feature set (JSONB, foreign tables, arrays), while the data mapper pattern is much lower-impact than object-relational mapping. Its goal is to be intuitive and unobtrusive -- it introspects your database on startup and builds an API for you, but if you need to do something it doesn't cover it won't get in your way.

Collapse
 
dangolant profile image
Daniel Golant

It's the type hinting/enforcement that I am looking for actually, because I find JS to be a bit too loose. Thanks for the tip! I am looking at KnexJS to just build queries for me without worrying about models (I agree, needless overhead) but I will have to look at Massive!