Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active December 28, 2019 22:38
Show Gist options
  • Select an option

  • Save twolfson/13eeeb547271c8ee32707f7b02c2ed90 to your computer and use it in GitHub Desktop.

Select an option

Save twolfson/13eeeb547271c8ee32707f7b02c2ed90 to your computer and use it in GitHub Desktop.
Node.js ORM evaluation

We are planning on building a Node.js service. Here's our evaluation of the current ORM landscape:

Last updated: May 2 2016

Our likely choice is sequelize (possibly with callback bindings via bluebird-nodeify)

@koskimas
Copy link

@jamespedid Here's the objection equivalent of your example.

const { MyModel } = require('./models/MyModel')

MyModel.query().eager('orders')

here's a four layers deep association fetch

const { MyModel } = require('./models/MyModel')

MyModel.query().eager('orders.someRelation.somethingElse.evenDeeperRelation')

Could you please elaborate what you mean by goofy magic and stuff?

@jamespedid
Copy link

First goofy thing: 'orders' is the name of the SQL table. Why am i littering everywhere in my code with the names of tables? Isn't the ORM supposed to abstract away such details? Even worse, what if I have to change the table in the database? Not unheard of, pretty common as applications tend to age actually. Maybe I'm refactoring and moving schemas. Having implementation details of the database bleed into my code everywhere is a huge problem for me.

Second goofy thing: the awkward DSL of using something like '[why,is,this,an,array,in,a,string]' to eagerly fetch over these entities? Again, incredibly hard to work with in a long-term setting. Having tokenizable, refactorable pieces in a way that is convenient is a big deal. I could use something like [${Why.tableName},${Is.tableName},...], but this is already becoming far more cumbersome than sequelize.

Copy link

ghost commented May 12, 2019

@jamespedid orders is not the SQL table name, it is the relation name defined under MyModel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment