typeorm vs sequelize vs knex vs bookshelf
Node.js ORM Libraries Comparison
3 Years
typeormsequelizeknexbookshelfSimilar Packages:
What's Node.js ORM Libraries?

Node.js ORM libraries provide developers with an abstraction layer for interacting with databases, allowing them to work with database records as JavaScript objects. These libraries facilitate the management of database queries, relationships, and migrations, enhancing productivity and code maintainability. Each library has its unique features and design philosophies, catering to different project requirements and developer preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
typeorm2,579,754
35,74320.7 MB2,48716 days agoMIT
sequelize2,396,882
30,1512.91 MB9845 months agoMIT
knex2,377,551
19,989874 kB1,0132 years agoMIT
bookshelf71,807
6,368-2375 years agoMIT
Feature Comparison: typeorm vs sequelize vs knex vs bookshelf

Database Support

  • typeorm:

    TypeORM supports various SQL databases like MySQL, PostgreSQL, MariaDB, SQLite, and Microsoft SQL Server, and also offers support for MongoDB, making it a flexible choice for different database types.

  • sequelize:

    Sequelize supports a wide range of SQL databases including PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server, providing a robust solution for diverse database environments.

  • knex:

    Knex is primarily a SQL query builder that supports multiple databases such as PostgreSQL, MySQL, SQLite, and Oracle, allowing developers to write database-agnostic queries.

  • bookshelf:

    Bookshelf supports various SQL databases through Knex.js, including PostgreSQL, MySQL, and SQLite, making it versatile for different project needs.

Learning Curve

  • typeorm:

    TypeORM has a moderate to steep learning curve, particularly for those unfamiliar with TypeScript or decorators, but it provides a rich set of features that can be very beneficial for complex applications.

  • sequelize:

    Sequelize has a steeper learning curve due to its extensive feature set and conventions, but it offers comprehensive documentation and examples to help new users get started.

  • knex:

    Knex has a moderate learning curve, as it requires understanding SQL syntax and query building, but its flexibility allows developers to gradually learn as they build more complex queries.

  • bookshelf:

    Bookshelf has a relatively low learning curve, especially for those familiar with Knex.js, as it provides a simple API for defining models and relationships without overwhelming complexity.

Extensibility

  • typeorm:

    TypeORM provides a robust extensibility model with decorators, custom repositories, and event listeners, allowing developers to create highly customized data models and interactions.

  • sequelize:

    Sequelize offers a variety of hooks and lifecycle events that allow for extensive customization and extensibility, enabling developers to implement complex business logic easily.

  • knex:

    Knex is highly extensible, allowing developers to create custom query builders and plugins, making it suitable for projects that require unique database interactions.

  • bookshelf:

    Bookshelf is extensible through plugins and custom model methods, allowing developers to tailor the ORM to their specific needs without significant overhead.

Performance

  • typeorm:

    TypeORM is optimized for performance, particularly in TypeScript applications, but it can introduce some overhead with its advanced features. Proper configuration and usage patterns can help mitigate performance issues.

  • sequelize:

    Sequelize provides good performance for most applications, but its extensive feature set can introduce overhead. Proper indexing and query optimization are essential for maintaining performance.

  • knex:

    Knex is designed for performance, allowing developers to write optimized SQL queries directly, which can lead to better performance in high-load scenarios.

  • bookshelf:

    Bookshelf's performance is generally good for most applications, but it may not be as optimized for large-scale applications compared to more complex ORMs due to its simplicity.

Community and Support

  • typeorm:

    TypeORM has a growing community, especially among TypeScript developers, with good documentation and community support, although it may not be as large as Sequelize's.

  • sequelize:

    Sequelize boasts a large and active community, with extensive documentation, tutorials, and third-party resources available, making it easy to find help and examples.

  • knex:

    Knex has a strong community and is widely used, providing ample resources, documentation, and community support for developers.

  • bookshelf:

    Bookshelf has a smaller community compared to others, but it benefits from the Knex.js community for support and resources.

How to Choose: typeorm vs sequelize vs knex vs bookshelf
  • typeorm:

    Choose TypeORM if you are working with TypeScript and need an ORM that fully integrates with it, offering decorators and a powerful entity management system. It's suitable for complex applications that require advanced features like lazy loading and caching.

  • sequelize:

    Opt for Sequelize if you need a feature-rich ORM that supports multiple SQL dialects, offers a wide range of built-in functionalities like migrations, validations, and associations, and has a strong community and documentation for support.

  • knex:

    Select Knex if you need a flexible SQL query builder that allows you to write raw SQL queries while still providing some ORM-like features. It's ideal for projects where you want fine-grained control over SQL syntax and database interactions.

  • bookshelf:

    Choose Bookshelf if you prefer a simple and lightweight ORM that is built on top of Knex.js, providing a straightforward way to manage relations and models without the complexity of a full-fledged ORM.

README for typeorm

TypeORM is an ORM that can run in Node.js, Browser, Cordova, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used with TypeScript and JavaScript (ES2021). Its goal is to always support the latest JavaScript features and provide additional features that help you to develop any kind of application that uses databases - from small applications with a few tables to large-scale enterprise applications with multiple databases.

TypeORM supports more databases than any other JS/TS ORM: Google Spanner, Microsoft SqlServer, MySQL/MariaDB, MongoDB, Oracle, Postgres, SAP HANA and SQLite, as well we derived databases and different drivers.

TypeORM supports both Active Record and Data Mapper patterns, unlike all other JavaScript ORMs currently in existence, which means you can write high-quality, loosely coupled, scalable, maintainable applications in the most productive way.

TypeORM is highly influenced by other ORMs, such as Hibernate, Doctrine and Entity Framework.

Features

  • Supports both DataMapper and ActiveRecord (your choice).
  • Entities and columns.
  • Database-specific column types.
  • Entity manager.
  • Repositories and custom repositories.
  • Clean object-relational model.
  • Associations (relations).
  • Eager and lazy relations.
  • Unidirectional, bidirectional, and self-referenced relations.
  • Supports multiple inheritance patterns.
  • Cascades.
  • Indices.
  • Transactions.
  • Migrations and automatic migrations generation.
  • Connection pooling.
  • Replication.
  • Using multiple database instances.
  • Working with multiple database types.
  • Cross-database and cross-schema queries.
  • Elegant-syntax, flexible and powerful QueryBuilder.
  • Left and inner joins.
  • Proper pagination for queries using joins.
  • Query caching.
  • Streaming raw results.
  • Logging.
  • Listeners and subscribers (hooks).
  • Supports closure table pattern.
  • Schema declaration in models or separate configuration files.
  • Supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / Oracle / SAP Hana / sql.js.
  • Supports MongoDB NoSQL database.
  • Works in Node.js / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms.
  • TypeScript and JavaScript support.
  • ESM and CommonJS support.
  • Produced code is performant, flexible, clean, and maintainable.
  • Follows all possible best practices.
  • CLI.

And more...

With TypeORM, your models look like this:

import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"

@Entity()
export class User {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    firstName: string

    @Column()
    lastName: string

    @Column()
    age: number
}

And your domain logic looks like this:

const userRepository = MyDataSource.getRepository(User)

const user = new User()
user.firstName = "Timber"
user.lastName = "Saw"
user.age = 25
await userRepository.save(user)

const allUsers = await userRepository.find()
const firstUser = await userRepository.findOneBy({
    id: 1,
}) // find by id
const timber = await userRepository.findOneBy({
    firstName: "Timber",
    lastName: "Saw",
}) // find by firstName and lastName

await userRepository.remove(timber)

Alternatively, if you prefer to use the ActiveRecord implementation, you can use it as well:

import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm"

@Entity()
export class User extends BaseEntity {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    firstName: string

    @Column()
    lastName: string

    @Column()
    age: number
}

And your domain logic will look this way:

const user = new User()
user.firstName = "Timber"
user.lastName = "Saw"
user.age = 25
await user.save()

const allUsers = await User.find()
const firstUser = await User.findOneBy({
    id: 1,
})
const timber = await User.findOneBy({
    firstName: "Timber",
    lastName: "Saw",
})

await timber.remove()

Samples

Take a look at the samples in sample for examples of usage.

There are a few repositories that you can clone and start with:

Extensions

There are several extensions that simplify working with TypeORM and integrating it with other modules:

Contributing

Learn about contribution here and how to set up your development environment here.

This project exists thanks to all the people who contribute:

Sponsors

Open source is hard and time-consuming. If you want to invest in TypeORM's future, you can become a sponsor and allow our core team to spend more time on TypeORM's improvements and new features. Become a sponsor

Gold Sponsors

Become a gold sponsor and get premium technical support from our core contributors. Become a gold sponsor