Node.js Knex与Sequelize有何相似/不同? [英] How is Node.js Knex similar/different to Sequelize?

查看:740
本文介绍了Node.js Knex与Sequelize有何相似/不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从IRC频道获得的答案:

The answer I got from an IRC channel:

Sequelize是一个ORM,其中包含一些查询生成器内容; Knex是仅仅是一个查询生成器,而不是ORM.

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

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?

推荐答案

Sequelize是完整的ORM,迫使您将SQL隐藏在对象表示后. Knex是简单的查询生成器,对于应用程序开发来说,它是太低级的工具.

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.

更好地使用objection.js,它结合了ORM的大部分功能,而不会影响编写任何类型的SQL查询的能力.

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

这是objection.js的作者写的一篇很好的文章. https://www.jakso.me/blog/objection-to-orm-hatred

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

免责声明:我是knex维护者,还参与了objection.js的开发.

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

这篇关于Node.js Knex与Sequelize有何相似/不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆