How is Node.js Knex similar/different to Sequelize

2020-08-10 06:48发布

The answer I got from an IRC channel:

Sequelize is an ORM that includes some query builder stuff; Knex is just a query builder, not an ORM.

ORMs don't actually fit very well in many use cases, it's easy to run up against the limits of what they can express, and end up needing to break your way out of them.

But that doesn't really explain the pros and cons of each. I am looking for an explanation, and possibly a simple example (use case) highlighting those similarities / differences.

Why would one use one over the other?

1条回答
我命由我不由天
2楼-- · 2020-08-10 07:44

Sequelize is full blown ORM forcing you to hide SQL behind object representation. Knex is plain query builder, which is way too low level tool for application development.

Better to use objection.js it combines good parts of ORMs without compromising power of writing any kind of SQL queries.

Here is good article about it from the author of objection.js https://www.jakso.me/blog/objection-to-orm-hatred

Disclaimer: I'm knex maintainer and been also involved in development of objection.js.

查看更多
登录 后发表回答