How is Node.js Knex similar/different to Sequelize?

偶尔善良 提交于 2020-06-25 08:40:07

问题


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:


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.



来源:https://stackoverflow.com/questions/56028287/how-is-node-js-knex-similar-different-to-sequelize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!