Choosing how you connect to a database through nodejs can make a big difference both in development time, security, stability and data integrity. What you’re looking for in an ORM (Object-relational mapping) tool depends of course on your project needs.
In this post we’ll go over the major ORM tools for nodejs and help you pick the right one for your project.
An ORM for Node.js and the Sails framework. It was authored on Dec, 2012.
It provides a uniform API for accessing stuff from different kinds of databases, protocols, and 3rd party APIs. That means you write the same code to get and store things like users, whether they live in Redis, mySQL, LDAP, MongoDB, or Postgres.
Waterline strives to inherit the best parts of ORMs like ActiveRecord, Hibernate, and Mongoose, but with a fresh perspective and emphasis on modularity, testability, and consistency across adapters.
Knex.js is a “batteries included” SQL query builder for Postgres, MSSQL, MySQL, MariaDB, SQLite3, and Oracle designed to be flexible, portable, and fun to use. It features both traditional node style callbacks as well as a promise interface for cleaner async flow control, a stream interface, full featured query and schema builders, transaction support (with savepoints), connection pooling and standardized responses between different query clients and dialects.
Control mongoDB databases through nodejs.
Multi dialect ORM for Node.JS/io.js. It was created May, 2011.
Sequelize is a promise-based ORM for Node.js and io.js. It supports the dialects PostgreSQL, MySQL, MariaDB, SQLite and MSSQL and features solid transaction support, relations, read replication and more.
A lightweight ORM for PostgreSQL, MySQL, and SQLite3. Created Apr, 2013.
It is designed to work well with PostgreSQL, MySQL, and SQLite3.
ORM for Node.js. It was authored on Jun, 2012.
Objection gives you:
What objection.js gives you:
What objection.js doesn’t give you:
- A custom query DSL. SQL is used as a query language.
- Automatic database schema creation and migration. For simple things it is useful that the database schema is automatically generated from the model definitions, but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things to you. knex has a great migration tool that we recommend for this job. Check out the example project.
Objection.js uses Promises and coding practices that make it ready for the future. We use Well known OOP techniques and ES2015 compatible classes and inheritance in the codebase. You can use things like async/await using a transpiler such as Babel. Check out our ES2015 and ESNext example projects.