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

Node.js ORM libraries provide an abstraction layer for interacting with databases, allowing developers to work with data using JavaScript objects instead of SQL queries. These libraries facilitate database operations such as creating, reading, updating, and deleting records, while also offering features like relationships, migrations, and schema definitions. By using an ORM, developers can write cleaner and more maintainable code, as well as benefit from built-in features like validation and transaction management.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
typeorm2,568,045
35,75620.7 MB2,49019 days agoMIT
sequelize2,305,804
30,1522.91 MB9845 months agoMIT
objection173,734
7,341645 kB124a year agoMIT
bookshelf72,034
6,368-2375 years agoMIT
Feature Comparison: typeorm vs sequelize vs objection vs bookshelf

Database Support

  • typeorm:

    TypeORM supports a wide range of databases, including MySQL, PostgreSQL, MariaDB, SQLite, and Microsoft SQL Server. Its strong TypeScript integration allows for seamless database interactions with type safety.

  • sequelize:

    Sequelize offers extensive support for multiple SQL dialects, including PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server. Its versatility makes it a popular choice for developers needing cross-database compatibility.

  • objection:

    Objection.js also supports PostgreSQL, MySQL, and SQLite, leveraging Knex.js for query building. It excels in handling complex queries and relationships, making it suitable for applications with intricate data structures.

  • bookshelf:

    Bookshelf supports SQL databases through Knex.js, primarily focusing on PostgreSQL, MySQL, and SQLite. It provides a straightforward API for defining models and relationships, making it easy to work with these databases.

Learning Curve

  • typeorm:

    TypeORM's learning curve can be steep for those unfamiliar with TypeScript or decorators. However, its comprehensive documentation and TypeScript support provide a solid foundation for developers looking to leverage its full potential.

  • sequelize:

    Sequelize has a steeper learning curve due to its extensive feature set and configuration options. However, its detailed documentation and community support can help mitigate this challenge for developers willing to invest time in learning.

  • objection:

    Objection.js has a moderate learning curve, as it introduces more advanced features compared to Bookshelf. Developers familiar with Knex.js will find it easier to grasp, but newcomers may need time to understand its capabilities.

  • bookshelf:

    Bookshelf has a relatively gentle learning curve, making it accessible for developers new to ORMs. Its simplicity allows for quick adoption, especially for small to medium-sized projects.

Eager Loading

  • typeorm:

    TypeORM supports eager loading through its relations option, allowing developers to specify which related entities to load with the main entity. This feature is particularly useful for applications with complex data relationships.

  • sequelize:

    Sequelize includes built-in support for eager loading through its include option, allowing developers to specify related models to fetch alongside the main query. This feature is essential for optimizing data retrieval in complex applications.

  • objection:

    Objection.js offers robust support for eager loading, enabling developers to load related models efficiently. It provides a powerful syntax for defining relationships and fetching related data in a single query, enhancing performance.

  • bookshelf:

    Bookshelf supports eager loading of related models, allowing developers to fetch associated data in a single query. This feature helps optimize database interactions and reduces the number of queries needed to retrieve related data.

Migrations

  • typeorm:

    TypeORM includes a powerful migration system that allows developers to create, run, and revert migrations directly within the framework. This feature is particularly beneficial for maintaining database schema consistency in TypeScript applications.

  • sequelize:

    Sequelize has a robust migration system built-in, allowing developers to easily create, manage, and apply migrations. This feature simplifies the process of evolving the database schema over time and is a significant advantage for larger projects.

  • objection:

    Objection.js also relies on Knex.js for migrations, meaning developers must manage migrations separately. While this provides flexibility, it may require additional effort to set up and maintain migration scripts.

  • bookshelf:

    Bookshelf does not include built-in migration support, but it can be used with Knex.js migrations. This requires additional setup for managing database schema changes, which may be a drawback for some developers.

Community and Ecosystem

  • typeorm:

    TypeORM has a strong community, particularly among TypeScript developers. Its comprehensive documentation and active GitHub repository provide ample resources for learning and troubleshooting, making it a reliable choice for TypeScript-based applications.

  • sequelize:

    Sequelize boasts a large and active community, providing extensive documentation, tutorials, and third-party plugins. Its popularity among developers ensures a wealth of resources and support for troubleshooting and best practices.

  • objection:

    Objection.js has a growing community and is well-supported by the Knex.js ecosystem. Its focus on advanced features and flexibility makes it appealing for developers looking for a more powerful ORM solution.

  • bookshelf:

    Bookshelf has a smaller community compared to some other ORMs, but it benefits from the Knex.js ecosystem. Its simplicity and lightweight nature make it a good choice for smaller projects or those with less complex requirements.

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

    Choose TypeORM if you are working in a TypeScript environment and want an ORM that fully embraces TypeScript's features. It supports both Active Record and Data Mapper patterns, making it versatile for different architectural styles, and is ideal for applications that require strong typing and decorators.

  • sequelize:

    Choose Sequelize if you want a comprehensive ORM with extensive support for various SQL dialects, including MySQL, PostgreSQL, and SQLite. It provides a rich set of features, including migrations, validation, and hooks, making it a great choice for applications that require robust database management.

  • objection:

    Choose Objection.js if you need a powerful ORM that supports complex queries and relationships while still being built on Knex.js. It offers a more feature-rich experience than Bookshelf, including support for eager loading and transactions, making it suitable for larger applications.

  • bookshelf:

    Choose Bookshelf if you prefer a simple, lightweight ORM with a focus on simplicity and flexibility. It is built on top of Knex.js and is ideal for projects that require a straightforward approach to database interactions without the need for complex features.

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