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?
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.
Knex. js is a “batteries-included” query builder for PostgreSQL, MySQL, SQLite3, Oracle, Amazon Redshift, and many other database drivers. We simply install the Knex library and the appropriate driver to query the database. Primarily made for Node. js, Knex supports both Node-style callbacks and promises.
Knex is a technique that is used to build queries. It supports various databases like Postgres, MySQL, SQLite, Oracle, and some others as well. It provides both callbacks and promise interface. It provides connection pooling and standardized responses.
Sequelize is a Node. js-based Object Relational Mapper that makes it easy to work with MySQL, MariaDB, SQLite, PostgreSQL databases, and more. An Object Relational Mapper performs functions like handling database records by representing the data as objects.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With