We are planning on building a Node.js service. Here's our evaluation of the current ORM landscape:
Last updated: May 2 2016
- Objection.js
- http://vincit.github.io/objection.js/#introduction
- Bad: API is Promise based and bulky. This means people can forget to have an error handler due to not being error first
- Good: Uses JSON schema for validation; this means content should be relatively reusable between server/browser
- Good: Has nice syntax for relationships
- Good: Built on knex.js which seems to be canonical SQL driver
- Neutral: Recommends using Knex.js' migration tool for migrations
- Good: Well maintained
- http://isitmaintained.com/project/Vincit/objection.js
- Resolution time: 1 day, Open issues: 13%
- http://isitmaintained.com/project/Vincit/objection.js
- Sails
- https://github.com/balderdashy/sails
- Not looking for an opinionated MVC, skipping for now
- Waterline, ORM from Sails
- https://github.com/balderdashy/waterline
- Bad: Response time takes a while
- But might be well supported since Sails?
- http://isitmaintained.com/project/balderdashy/waterline
- Resolution time: 10 days, Open issues: 2%
- sequelize
- https://github.com/sequelize/sequelize
- Good: Syntax is clean and straightforward
- Good: Seems to have everything we need (e.g. relationships, validation)
- TODO: There might be callback support via
nodeify - Good: Well maintained
- http://isitmaintained.com/project/sequelize/sequelize
- Resolution time: 1 day, Open issues: 12%
- http://isitmaintained.com/project/sequelize/sequelize
- Bookshelf.js
- http://bookshelfjs.org/
- Good: Feels very Backbone.js-esque (e.g.
get/set, virtual properties (similar tobackbone-relationship)) - Good: Supports callbacks
- Good: Authored by knex.js author
- Bad: Maintenance isn't great
- http://isitmaintained.com/project/tgriesser/bookshelf
- Resolution time: 6 days, Open issues: 28%
- http://isitmaintained.com/project/tgriesser/bookshelf
- orm2
- https://github.com/dresende/node-orm2
- Used it previously, had a terrible experience
Our likely choice is sequelize (possibly with callback bindings via bluebird-nodeify)
I can't fathom how anyone would say that Objection is a good ORM and Sequelize is a bad ORM. Objection has so many bad practices going for it, it's practically a nightmare. Now there is a disclaimer that I've used Sequelize for much longer than Objection, but just from an API perspective I absolutely loathe Objection. Building it as an extension to Knex.js is just a terrible idea for an ORM.
For those who are having trouble with Sequelize's ORM for associations, what is difficult about:
Hell, even if you have to do three or four associations deep, it isn't hard because you just add more objects with more includes. Constrast that to Objections, where I have to lay out the join ahead of time. Add in some goofy relationship 'magic' and you have a mess on your hands.
Raw SQL? Sequelize makes it a breeze to execute a raw query and map them to a model. And the queries that Sequelize generate typically are good (except for a few questionable subquery choices, but you can remedy these with a simple subQuery: true option.)