typeorm vs sequelize-typescript vs @nestjs/sequelize
Node.js ORM Libraries Comparison
3 Years
typeormsequelize-typescript@nestjs/sequelizeSimilar Packages:
What's Node.js ORM Libraries?

Node.js ORM libraries provide developers with tools to interact with databases using object-oriented programming principles. They abstract the complexities of SQL queries and database interactions, allowing developers to work with JavaScript objects instead of raw SQL. This enhances productivity, maintainability, and readability of the code, especially in large applications. Each of these libraries offers unique features and integrations, making them suitable for different project requirements and preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
typeorm2,586,110
35,74920.7 MB2,49017 days agoMIT
sequelize-typescript374,511
2,834216 kB2642 years agoMIT
@nestjs/sequelize112,976
25931.4 kB58 months agoMIT
Feature Comparison: typeorm vs sequelize-typescript vs @nestjs/sequelize

TypeScript Support

  • typeorm:

    TypeORM is fully written in TypeScript and offers comprehensive support for TypeScript features, allowing developers to leverage strong typing and decorators for defining entities and relationships.

  • sequelize-typescript:

    sequelize-typescript is designed specifically for TypeScript, offering decorators and type definitions that make it easy to define models and relationships, ensuring a more robust development experience with TypeScript's features.

  • @nestjs/sequelize:

    @nestjs/sequelize provides seamless integration with TypeScript, allowing developers to define models and database interactions using TypeScript decorators, enhancing type safety and reducing runtime errors.

Integration with Frameworks

  • typeorm:

    TypeORM is framework-agnostic and can be used with various Node.js frameworks, including Express and NestJS. It provides flexibility in how you structure your application while offering powerful ORM features.

  • sequelize-typescript:

    sequelize-typescript can be used independently but is often integrated into Express or similar frameworks. It provides a straightforward way to define models and interact with the database, but lacks the specific framework integrations found in NestJS.

  • @nestjs/sequelize:

    @nestjs/sequelize is tailored for NestJS applications, providing decorators and modules that integrate seamlessly with the NestJS ecosystem, making it ideal for building scalable server-side applications.

Query Building

  • typeorm:

    TypeORM offers a powerful query builder that supports both SQL-like syntax and a fluent API, allowing for complex queries and aggregations, making it suitable for applications with intricate data requirements.

  • sequelize-typescript:

    sequelize-typescript inherits Sequelize's query building features, providing a rich set of methods for constructing queries and handling relationships, making it easy to perform CRUD operations.

  • @nestjs/sequelize:

    @nestjs/sequelize utilizes Sequelize's powerful query building capabilities, allowing developers to construct complex queries using a fluent API, which simplifies database interactions.

Migrations

  • typeorm:

    TypeORM has a robust migration system built-in, allowing developers to create, run, and revert migrations easily, providing a comprehensive solution for managing database schema changes.

  • sequelize-typescript:

    sequelize-typescript supports migrations as part of the Sequelize ecosystem, enabling developers to create and run migrations to keep the database schema in sync with application changes.

  • @nestjs/sequelize:

    @nestjs/sequelize supports migrations through Sequelize, allowing developers to manage database schema changes easily and maintain version control over database structures.

Community and Ecosystem

  • typeorm:

    TypeORM has a large and active community, with extensive documentation and a variety of resources available, making it easier for developers to find support and examples.

  • sequelize-typescript:

    sequelize-typescript has a smaller community compared to Sequelize but benefits from the established Sequelize ecosystem, which includes various plugins and extensions.

  • @nestjs/sequelize:

    @nestjs/sequelize benefits from the growing NestJS community, which provides extensive documentation, tutorials, and support for developers building applications with NestJS.

How to Choose: typeorm vs sequelize-typescript vs @nestjs/sequelize
  • typeorm:

    Select TypeORM if you need a versatile ORM that supports both Active Record and Data Mapper patterns, along with a rich set of features like migrations, caching, and support for various databases. TypeORM is particularly suited for applications that require complex queries and relationships.

  • sequelize-typescript:

    Opt for sequelize-typescript if you prefer TypeScript support with Sequelize and want to take advantage of decorators for defining models, which can lead to cleaner and more maintainable code. This package is ideal for projects that heavily utilize TypeScript and require a strong type system.

  • @nestjs/sequelize:

    Choose @nestjs/sequelize if you are developing a NestJS application and want to leverage Sequelize's capabilities with built-in support for dependency injection and decorators, making it easier to manage database interactions in a modular way.

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