Translated from www.prisma.io/dataguide/d…

Database tool

The top 11 Node.js ORM and SQL generators in 2020

content

  • introduce
  • Evaluate database library conditions
  • SQL, SQL generator, and ORM
  • Prisma
  • Sequelize
  • TypeORM
  • Mongoose
  • Bookshelf.js
  • Objection.js
  • Waterline
  • Knex.js (SQL generator)
  • other
  • conclusion

introduce

Choosing ORM or query generator for Node.js applications can be daunting. There are many different libraries that let you query and manipulate data from JavaScript applications, and each has a different level of design and abstraction.

This article is intended as a starting point for selecting a library and summarizing the data that developers will look for before selecting tools for their projects. It tries to maintain objectivity and make as few value judgments as possible.

It doesn’t try to pick “one best library” or rank packages in a self-righteous way. Instead, it summarizes the most popular Node.js query generators, ORM, and database toolkits and describes their project health. This is done based on popularity, buyback activity, developer support, and project maturity.

Evaluate database library conditions

This article focuses on the most popular Node.jssQL, ORM, and database toolkits. Finally, database drivers and newer libraries will be briefly considered. Type safety and TypeScript support are outside the scope of this article and will be evaluated in a future article.

The library will conduct a brief summary and evaluation based on the following criteria:

standard describe evaluators
Popularity of How popular is the library among developers? GitHub star, NPM download andCompound growth rate month by monthOnce the download
Repurchase activity How active is development in buybacks? Submit, publish, merge PR and GitHub issues
support Will developers be well supported? Document quality, StackOverflow and Reddit status, Gitter/Slack/IRC channels and GitHub issues
Maturity and stability How new is this project? Is it stable and supported by its supporters? NPM modules and GitHub repositories, maintenance, financial investment, enterprise support and production use cases

The data months considered in this article are From August 7, 2020 to September 7, 2020. Note that the packages on this page are not displayed in a specific order, which means that the list does not represent a specific ranking.

This standard is not exhaustive, and you should choose the tool that best suits your project and programming preferences.

SQL, SQL generator, ORM

Libraries for querying and manipulating data can be broadly divided into three categories, each operating at a different level of abstraction.

From lowest to highest:

  • Database drivers, clients, and connectors, such as Node-Postgres
  • An SQL builder, such as knex.js, runs on top of the database client and allows you to write JavaScript code to process and query data
  • Such asThe SequelizeClass object relational mapping tool (ORM) and otherOf PrismaClass database toolkit that developers can usemodel, the abstract entity corresponding to the database table

Many tools blur the line between the two and allow developers to drop to a lower level when additional flexibility or control is needed. For more information, consult Prisma’s Data Guide for comparison SQL, SQL Builder, and ORM.

Prisma

To assess the

  • Popularity: popularity
  • Buyback activity: Very active
  • Strong support:
  • ** Maturity and stability: ** relatively new
  • Supported databases: MySQL, PostgreSQL and SQLite (more planned)

The overview

  • Web site
  • GitHub
  • NPM: @ Prisma/CLI

Prisma differs from most ORMs in that, instead of defining models in classes, they are defined in Prisma schemas, the main configuration and data model definition file used by the Prisma toolkit. In the Prisma schema, you define data sources (such as the PostgreSQL database) and models (such as Users and) posts and the relationships between them. With this architecture, Prisma generates a client that exposes a create-read-update-delete (CRUD) API that you can then use to query the database. The Prisma Client acts as a rich SQL builder that you can use in Node.js applications to return pure JavaScript objects rather than instances of model classes.

Popularity of

Prisma, with 5.1K stars on the Prisma GitHub repository, is a popular database tool for Node developers, comparable to established libraries such as Bookshelf.js and objection.js, But not as popular GitHub stars as 20K libraries like Sequelize and TypeORM. It should be noted that Prisma only started production in June 2020, while most of the other tools have been around for a few years.

In terms of NPM downloads, there are about 238,000 downloads per month, comparable to tools like Bookshelf.js and station.js, but not in the same tier as Sequelize, TypeORM, and Mongoose. However, of all the major tools considered in this article, its growth rate is high, with NPM downloads growing at 7% per month. By comparison, most other tools are growing at around 4.5 percent a month, with bookshelf.js growing at 8 percent.

** Comments: ** is popular

Repurchase activity

It’s safe to say that the Prisma GitHub repository is the most active of all the tools considered in this article. Prisma has 194 commits, 5 releases, and 53 consolidated PR in the data months considered in this article, so is actively developing heavily and pushing new features, bug fixes, and updates frequently.

** comments: ** is very active

support

Although Prisma is younger than some of the other tools considered here, it benefits from a strong and active developer support network. Its documentation is well-organized, actively expanding, and very detailed.

If you have a question, use the Prisma Slack channel, ask a question on its GitHub discussion page, or submit a GitHub Issue, all of which are active. While there isn’t much StackOverflow question library to draw from, the library of answered queries about GitHub discussions and Reddit isn’t enough to make up for it.

** Evaluation: ** strong

Maturity and stability

Prisma was first created and released in 2016, making it one of the newer tools considered for this article. It has undergone several iterations and redesigns, starting with Graphcool, which stands for GraphQL backend as a service. Graphcool then moved into the database and GraphQL tool and became Prisma 1.0, a very popular project with 19,000 GitHub stars. Prisma 2.0 was released in Beta earlier this year, then moved away from the Prisma server and GraphQL layer to become today’s alternative to JavaScript and TypeScript ORM.

Prisma 2.0 is an open source JavaScript database tool maintained, supported, and actively developed by privately held Prisma, which recently closed A $12 million Series A funding round. Prisma employs professional engineers, developer advocates, technical writers, and others to maintain and build Prisma. This means that when Prisma is implemented as its JavaScript database interface, you can ensure that developers will be well supported.

** Evaluation: ** is newer

Database support

Prisma currently supports PostgreSQL, MySQL, and SQLite.

features

  • Use JavaScript objects directly instead of classes and instances
  • Prisma model of “single fact source” to reduce object relation impedance mismatches
  • Type-safe database queries
  • Auto-generated migration (experimental)
  • Intuitive relationship API
  • VSCode plug-in
  • Automatic completion support

For a complete list of features, see database features in the official Prisma documentation.

Use examples

Relational query (get all posts for a given user, E-mail for a given user) :

const postsByUser = await prisma.user.findOne({ where: { email: '[email protected]' } }).posts()
Copy the code

The profile

Although Prisma is an updated database tool that has been iterated and redesigned many times, its unique, architecture-centric architecture stands in sharp contrast to typical ORMs that use JavaScript class definition models. It benefits from the support of funded companies and paid developers, as well as an active support community and a fast development cycle. It’s a popular, fast-growing option that’s been around forever.

Sequelize

To assess the

  • Popularity: Very popular
  • Buyback activity: a little active
  • Support: average
  • Maturity and stability: ** is very mature
  • Supported databases: MySQL, MariaDB, SQLite and Microsoft SQL Server

The overview

  • Web site
  • GitHub
  • NPM: Sequelize

Sequelize is a mature, promise-based mature Node.js ORM that supports Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It follows the traditional ORM pattern of defining a Model by extending the Model class. Class methods are then used to perform operations like SELECT and INSERT. Relationships also use class methods such as hasMany() and define belongsTo().

Popularity of

Sequelize, with 22.8K GitHub Star and 3 million NPM downloads over the time period considered, is the most popular relational database ORM considered in this article. It’s still growing, with NPM downloads growing 4.4% a month over the past six months. By comparison, the second most popular relational database ORM is TypeORM, which has been downloaded 1.45 million times. (Mongoose is also popular, but only MongoDB.)

** Comments: ** is very popular

Repurchase activity

During the time period considered, a new version of Sequelize was released and six commits were pushed across all branches. Two PR’s were merged. This indicates that Sequelize is not dormant, but only active. Most of the recent activity has been around bugs and document fixes.

** Comments: ** is a bit active

support

It’s been around for almost a decade, and you’ll probably find support for Sequelize through StackOverflow or Reddit search. Its documentation is extensive, with many usage examples and some theoretical discussion of usage patterns (for example, its Associations document). However, Sequelize’s GitHub Issues and Slack channels can be useful, leaving many queries unanswerable.

** Evaluation: ** average

Maturity and stability

Sequelize is one of the most mature node ORMs available. It is no longer a fast-moving project, and recent development seems to be focused on bug fixes and documentation updates. It is a stable tool that relies entirely on open source contributions from maintainers and the Sequelize community.

According to its documentation, it has some notable users, such as WalmartLabs and Bitovi.

Evaluation: Very mature

Database support

Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It also supports CockroachDB using external packages.

features

  • Familiar with ORM interface and ActiveRecord usage patterns
  • Detailed control of transactions and how they are executed
  • Support for many databases
  • Ability to use multiple read-only copies
  • The relationship between desire and laziness
  • Synchronize the database according to the defined model

For a complete list of features, see the Sequelize official documentation.

Use examples

Relational query (all posts of a particular user, eager to load) :

const user = await User.findOne({
  where: {
    email: '[email protected]',},include: Post,
})
Copy the code

The profile

Sequelize is a stable stable ActiveRecord ORM, and due to its popularity and heavy use over the years, you can expect support from places like StackOverflow, Reddit, and GitHub Issues. However, the project has recently stalled and appears to be less active than before.

TypeORM

To assess the

  • Popularity: Very popular
  • Repurchase activity: Active
  • Support:
  • Maturity and stability: ** Mature
  • Supported databases: MySQL, MariaDB, PostgreSQL, CockroachDB, SQLite, Microsoft SQL Server, Oracle, SAP Hana, SQL.js

The overview

  • Web site
  • GitHub
  • NPM

TypeORM is a Hibernate-influenced JavaScript and TypeScript ORM that runs on multiple platforms, such as Node.js, Web browsers, and Cordova. It is built with TypeScript and type support in mind, and supports the two main ORM architectural patterns: Data Mapper and Active Record, giving developers the flexibility to choose between them. It also includes a query generator.

Popularity of

Since its release in 2016, TypeORM has rapidly grown into one of the most popular JavaScript and TypeScript ORM. It has 20,700 stars on GitHub and 1.4 million NPM downloads per month, making it one of The most popular ORM options for Sequelize and Mongoose.

** Comments: ** is very popular

Repurchase activity

TypeORM’s GitHub repository is active. In the past month, 29 commits were pushed to all branches and 26 PR were consolidated. There doesn’t seem to be a strict release schedule, with the latest release date being September 10, compared to the previous release date of May. Recent submissions include documentation additions and modifications, bug fixes, testing, and a mix of new features.

** Evaluation: ** active

support

TypeORM documentation is good, but it mostly consists of minimal usage examples, is familiar with ORM, and assumes that both database concepts (such as migration, relationships) and ORM schemas (such as Data Mapper and Active Record) can be used. When using TypeORM, you should be prepared to look for external resources and spend some time learning different usage patterns to implement it effectively in the stack. It has an active Slack community and has a moderate presence on Reddit and StackOverflow, but using GitHub questions is unlikely to get much help.

** Comments: ** good

Maturity and stability

Although comparable to Prisma in maturity, TypeORM’s design has changed since its initial release as a Hibernate-influenced ORM built for TypeScript (which is also very compatible with JavaScript). It relies entirely on open source contributions, but about $10,000 of OpenCollective’s annual contribution budget is supported. Notable corporate contributors include Cockroach Labs, Aplas and VoterCircle Inc.

** Evaluation: ** mature

Database support

MySQL, MariaDB, PostgreSQL, CockroachDB, SQLite, Microsoft SQL Server, Oracle, SAP Hana, SQL.js

features

  • Support for data mapper and active record ORM patterns
  • Powerful and flexible query generator
  • Powerful TypeScript support
  • Relationships are loaded with eagerness and laziness
  • Automatic migration generation
  • Transaction support
  • Support for many databases

For a complete list of features, see TypeORM GitHub README.

Use examples

Query all posts of a specific user in TypeORM:

const userRepository = getRepository(User)
const user = await userRepository.findOne(id, {
  relations: ['posts'],})Copy the code

The profile

TypeORM and Sequelize are two of the most popular relational database ORMs. TypeORM differs from Sequelize in that it provides more flexibility, allows you to choose between different usage patterns, and includes a powerful query generator. TypeORM supports a number of popular databases, and the project remains active despite being entirely dependent on its open source contributors.

Mongoose

To assess the

  • Popularity: Very popular
  • Repurchase activity: Active
  • Support:
  • Maturity and stability: ** Mature
  • Supported databases: MongoDB

The overview

  • Web site
  • GitHub
  • NPM

Mongoose is a popular and well-maintained Node.js object modeling tool for MongoDB. It allows you to model data using schemas and includes built-in type conversions, validation, query building, and business logic hooking.

Popularity of

Mongoose is the most popular JavaScript data modeling tool for MongoDB databases. It has 214,000 stars on GitHub and 4.1 million NPM downloads per month.

** Comments: ** is very popular

Repurchase activity

Mongoose’s GitHub repository is very active. In the past month, 69 submissions were made across branches and 9 PR were merged. Recent commits have focused on bug fixes and adding tests. Minor releases seem to be frequent, with six releases considered during this period.

** Evaluation: ** active

support

Mongoose’s documentation contains instructions for its most common operations, such as querying, creating models, and validating. The API documentation also contains many useful code snippets. It has a Slack and Gitter community (though both are relatively quiet), and you can expect to find a lot of support and tips on Reddit and StackOverflow. Its GitHub Questions section is also very active, with most questions receiving some kind of response or support from maintainers or other Mongoose users.

** Comments: ** good

Maturity and stability

Mongoose has been in existence since 2011, making it one of the most mature projects considered in this article. If you want to use node.js ODM with MongoDB, you can be confident that the Mongoose interface will not change radically and that it will be synchronized with the MongoDB version. It has substantial open source funding, with an annual budget of $110,000, entirely from OpenCollective contributors. Automattic, which owns WordPress.com, Tumblr and Simplenote, inherited Mongoose through a series of acquisitions. Terra Vera, SixPlus, and Payment Ninja all built with Mongoose.

** Evaluation: ** mature

Database support

MongoDB

features

  • The schema and model of your NoSQL database
  • Validators, middleware hooks back and forth
  • Other reference documents in the collectionpopulate()
  • Subdocuments: Nested schemas in other schemas

For a complete list of features, check the official Mongoose documentation.

Use examples

Relational query (get all posts for a given user, E-mail for a given user) :

const userWithPosts = await User.findOne({ email: '[email protected]' }).populate('posts')
Copy the code

The profile

If you use the MongoDB database with Node and want to use ODM, Mongoose is a good choice. This is a popular and mature project that will continue to be actively maintained. It allows you to define schemas for modeling data and provides features such as validation, type conversion, population, middleware, custom methods, and query helpers.

Bookshelf.js

To assess the

  • Popularity: popularity
  • Buyback activity: not very active
  • Support: average
  • Maturity and stability: ** Mature
  • Supported databases: PostgreSQL, MySQL, and SQLite

The overview

  • Web site
  • GitHub
  • Asl: shelf

Bookshelf.js is a Node.js ORM built on top of the Knex.jSSQL builder library. It is inspired by the Data Mapper ORM pattern and provides a simplified interface for modeling and interacting with Data.

Popularity of

Bookshelf.js, with 6,000 GitHub stars, is not as popular as Sequelize and TypeORM, but is in the same league as objection.js, Prisma and waterline.js. It has 408,000 downloads per month (compared to Sequelize’s 3 million), which means that while it may not be widely adopted, it still has a core base of developers who like a streamlined interface. It’s also growing at a high rate, with NPM downloads growing 8% per month. By comparison, most tools except Prisma (7 percent) grew at about 4.5 percent a month.

** Comments: ** is popular

Repurchase activity

In the past month, there have been no submissions, no posts, no merge requests in the Bookshelf repository. Recent submissions include some document cleanups, updates to bring it up to date with Knex.js, and some testing. At the time of this writing, the latest version is 1.2.06 7th.

** Comments: ** is not very active

support

Bookshelf’s core documentation includes a short quickstart guide and code snippets for creating different relationship types. However, the API documentation is extensive and contains many usage examples. There is an IRC channel on the shelf, but there are only seven members and it seems quiet. Similarly, support for StackOverflow and Reddit is light. The best choice is its GitHub Issues page.

** Evaluation: ** average

Maturity and stability

Bookshelf.js has been around since 2013 and is quite mature at this point. Its notable users include Ghost, Soapee, NodeZA, Sunday Cook and FlyptoX. It is an open source package with few maintenance staff and no financial or corporate backing.

** Evaluation: ** mature

Database support

PostgreSQL, MySQL and SQLite.

features

  • A lean interface with a streamlined ORM feature set
  • Built on top of knex.js, you can drop down and use the query generator as needed
  • Commitment and callback interfaces
  • Relationship loading of desires and nested desires
  • Support the deal
  • Community plug-ins to extend functionality

For a complete list of features, see the official bookshelf.js documentation.

Use examples

Relational query (get all posts for a given user, E-mail for a given user) :

const userWithPosts = awaitThe User. The where (" email ", "[email protected]"). The fetch ({withRelated: (" posts ")});Copy the code

The profile

Bookshelf.js is a simplified ORM that provides you with a standard set of data modeling, query, and manipulation tools. Because it is built on top of the Knex.jSSQL builder, you can always pull down and write more involved queries if you find yourself limited by its interface. It is not as active as some of the other tools considered in this article, but it has been around for a long time and has a core user base that likes its simplified style.

Objection.js

To assess the

  • Popularity: popularity
  • Buyback activity: a little active
  • Support:
  • Maturity and stability: ** Mature
  • Supported databases: SQLite, Postgres and MySQL

The overview

  • Web site
  • GitHub
  • NPM: objection

Self-description civ.js is more of a “relational query generator” than an ORM. Like Bookshelf.js, it’s built on top of the powerful Knex.jSSQL builder library, so you can build orM-like functionality on top of a flexible SQL builder that you can always use. Opposition to ORM Hatred, written by the creator of the object_.js library, is a brief summary of its design goals and its scope of application from raw SQL to ORM.

Popularity of

Files. Js has 5,500 GitHub stars and 325,000 NPM downloads per month, putting it close to Bookshelf.js and Prisma in terms of popularity, while Bookshelf is just above it. None of them are as popular as Sequelize and TypeORM, which both have 20K + downloads and a download range of 1 million +.

** Comments: ** is popular

Repurchase activity

For the period of time considered in this article, the object_.js repository has 7 commits and 6 merged PR. The last objection was posted on August 16 and included some documentation and bug fixes. Although not as active as projects like Prisma and TypeORM, it is actively maintained.

Verdict: A little active

support

Documentation for Objects consists of usage guides that cover its main functions, such as creating models and relationships, querying, transactions, hooks, and validation. It also contains API documentation and a “cookbook” that contains examples of common operations such as joins and subqueries. You won’t find much help on StackOverflow, but the project’s Gitter is quite active and supportive, it has a moderate presence on Reddit, and its maintainers often respond to GitHub issues.

** Comments: ** good

Maturity and stability

There have been objections since 2015 and this is a mature program. It does not appear to have any financial or corporate backing and is maintained by the open source community. For a list of production use cases for objection.js, see who Uses objection.js in Production? (Who uses objection.js in production?) .

** Evaluation: ** mature

Database support

SQLite, Postgres and MySQL

features

  • Built on knex.js
  • Eager to load
  • Transaction support
  • Validate the model against the JSON schema
  • Query hooks (pre/post insert, update, etc.)
  • Figure update
  • paging

For a complete list of features, refer to civic.js GitHub README.

Use examples

Relational query (get all posts for a given user, E-mail for a given user) :

const user = await User.query().findOne({
  email: '[email protected]'
});

const posts = await user
  .$relatedQuery('posts');
Copy the code

The profile

Content.js is most similar to Bookshelf.js in that it builds a set of OrM-like features on top of the Knex.jssQL builder library. Objection.js seems to be more actively maintained and better documented, and many objection.js developers have previously been based on [Who uses objection.js in production?] (Who uses objection.js in production?) In collaboration with Bookshelf.js.

Waterline

To assess the

  • Popularity: popularity
  • Buyback activity: not very active
  • Support: average
  • Maturity and stability: ** Mature
  • Supported databases: MySQL, PostgreSQL, and MongoDB Through community adapters: Redis, MS-SQL, Oracle, etc.

The overview

  • Web site
  • GitHub
  • NPM

Waterline is the default ORM used in the Sails Node.js framework. Part of its design is to allow you to use write once, use anywhere data manipulation code so that you can write code to query or manipulate data whether it is in MySQL, PostgreSQL, MongoDB, or any other database.

Popularity of

Waterline is a popular ORM with 5.2K GitHub Star and 124K NPM downloads per month. However, its downloads are growing at a slower rate than the other libraries considered in this article, averaging 1.33% monthly growth over the past six months (most are around 4%). Its 124K NPM downloads are also about half those of the likes of Bookhelf.js, Prisma, and civ.js.

** Comments: ** is popular

Repurchase activity

Recently, Waterline’s GitHub repository seems to have been less active, with 0 committed and merged PR in the data months under consideration. Its latest release is May 29, and the previous release was in February 2019. This latest version contains a commit bug fix.

** Comments: ** is not very active

support

If you encounter any problems with Waterline, you are likely to be alone. Its documentation is only a small part of the losa.js documentation, although its API is well documented and contains many usage examples. Additional support can be found on Sails Gitter (which seems to be active) and using GitHub Issues, although it will be on the GitHub Issues page of the Sails framework. However, it may take a while to get an answer to your question, or a fix may be pushed for your bug.

** Evaluation: ** average

Maturity and stability

Waterline has been around since 2013 and is a mature package with a stable API. As part of the Losa.js JavaScript framework, it is managed and maintained by Sails, Inc., a private company funded by seed money and incubated in the Y Combinator startup incubator. Losa.js is a popular JavaScript framework used by Verizon, Postman, JetBlue and others, but it is unclear how many production use cases rely on the separate Waterline library.

** Evaluation: ** mature

Database support

MySQL, PostgreSQL, MongoDB. Through community adapters: Redis, MS-SQL, Oracle, etc.

features

  • Write code that is not database related
  • Populate relationships between models, even if the data for different models resides in different databases

For a complete list of features, see the Waterline ORM GitHub README.

Use examples

Relational query (get all posts for a given user, E-mail for a given user) :

const userWithPosts = await User.find({ email: '[email protected]' }).populate('posts')
Copy the code

The profile

Waterline is the built-in ORM/ODM of the JavaScript framework losa.js, so its main goal is to support multiple database types (relational and NoSQL) without rewriting code. In recent months, the project has stalled, and the support is not as strong as some of the other libraries considered in this article.

Knex.js (Query Generator)

To assess the

  • Popularity: Very popular
  • Repurchase activity: Active
  • Support:
  • Maturity and stability: ** Mature
  • Supported databases: PostgreSQL, Amazon Redshift, MySQL, MariaDB, SQLite, MSSQL

The overview

  • Web site
  • GitHub
  • NPM

Knex.js is a Node.js query generator (not an ORM) that supports multiple databases and includes transaction support, connection pooling, and stream interfaces. It allows you to work at a level above the database driver without having to write SQL by hand. However, because it is a low-level library, you want to be familiar with SQL and relational database concepts, such as joins and indexes.

Popularity of

With 29,000 GitHub stars and 2.5 million NPM downloads per month, Knex.js is a very popular JavaScript query generator.

** Comments: ** is very popular

Repurchase activity

In the data months considered, Knex.js pushed 17 commits across all branches and committed in 14 combined PR. Two new versions of the library have been released. Recent commits include bug fixes and test improvements.

** Evaluation: ** active

support

The documentation for Knex.js consists mainly of a complete documentation of its API, which is extensive but fairly concise. Familiarity with relational databases, SQL and its core set of features (joins, transactions, joins, etc.) is expected. It hosts a seemingly dormant IRC channel, but you can find some support on StackOverflow and Reddit. Its GitHub Issues page seems to be very active, so you can make sure your query is available to project maintainers.

** Comments: ** good

Maturity and stability

Knex has been in existence since 2013 and is a mature project. It was designed as a “battery-inclusive” JavaScript query generator to support multiple database drivers, and its interface hasn’t changed much since then. This is a fully community-maintained open source project, and although it is not as active as some of the other libraries considered in this article, minor releases are frequent, and a small number of contributors continue to push for fixes and improvements to the library.

** Evaluation: ** mature

Database support

PostgreSQL, Amazon Redshift, MySQL, MariaDB, SQLite, MSSQL

features

  • Callback and commitment interface
  • Flow interface
  • Query and schema generator
  • Transaction support
  • The connection pool
  • Standardize responses between different query clients and dialects

For a complete list of features, see knex.js GitHub README.

Use examples

JOIN query (get all posts for a given user, email for a given user) :

const posts = await knex('posts')
  .join('users', { 'users.id': 'posts.user_id'.'users.email': '[email protected]' })
  .select(The '*')
Copy the code

The profile

Knex.js differs from most of the database tools considered in this article because it is not an ORM or abstraction layer that sits above the database to model the data. It is a powerful and flexible query generator that acts as a wrapper around database drivers, allowing you to simplify some queries and remove boilerplate SQL. It is the most popular “pure” JavaScriptSQL builder, and is a mature project that is actively maintained.

Other famous libraries

This article highlights some of the most popular Node.js ORMs, database tools, and query generators, but you may want to consider a few other tools for your project:

MassiveJS

  • Web site
  • Yabo Sports APP
  • NPM

MassiveJS is PostgreSQL’s Node.js database tool that builds abstractions for processing databases, but not full-fledged ORMs with models and entities. Like Prisma, it can connect to a database and perform internal checks to build apis for the data models encoded in the database. It includes dynamic query generator and transaction support, and was designed for PostgreSQL, thus supporting its unique set of features, such as array fields and operations, regular expression matching, external tables, and instantiated views.

The micro ORM

  • Web site
  • GitHub
  • NPM

Mikro-orm is a newer TypeScript ORM that also supports normal JavaScript. Because it is primarily a TypeScript ORM, it is not fully evaluated in this article. Mikro-orm is a fast growing project that is very active on GitHub and strongly supported by its developers. Influenced by Doctrine (PHP ORM), which is an ORM influenced by Data Mapper, Identity Map, and unit of work. Some of its features include automatic transaction processing, support for multiple databases, a built-in query generator based on Knex.js, and schema and entity generators.

, Nick

  • GitHub
  • NPM

Slonik is at some level above the Node-Postgres database driver. It is a collection of utilities built in for type safety, query emulation, join and transaction processing, detailed logging, value interpolation, and many other features. You still have to write raw SQL, but it’s designed to improve security and efficiency when using a PostgreSQL database. The library was released in 2017 and is still very active and supported on GitHub.

Database driver

The database driver sits at the lowest level of the abstract spectrum and can interact directly with the database using its query language. Overview Each Node.js database client is beyond the scope of this article, but for convenience, here are the main database drivers:

  • PostgreSQL: node-postgres, Pg-promise
  • MySQL: MySQL, node-mysql2, mysql-connector-nodejs
  • SQLite: node-sqlite3
  • MSSQL: node-sqlserver-v8, node-mSSQL, boring
  • Mongo: node – directing a native
  • Redis: node-redis ioredis

conclusion

This article summarizes the most popular Node.js ORMs, database toolkits, and query generators. Their health as open source projects is evaluated against criteria such as repository contributions and developer support.

It is not an exhaustive framework for selecting node.js database interfaces, and other factors such as the package’s programming interface, design, support for database functionality, and flexibility are more important than many of the criteria evaluated here. Different Node.js projects may require different tools.