typeorm vs sequelize vs objection vs bookshelf
Node.js ORMライブラリ
typeormsequelizeobjectionbookshelf類似パッケージ:
Node.js ORMライブラリ

ORM(Object-Relational Mapping)ライブラリは、データベースとアプリケーションコードの間のデータのやり取りを簡素化するためのツールです。これらのライブラリは、データベースの操作をオブジェクト指向の方法で行うことを可能にし、SQLクエリを直接書くことなくデータの取得や保存を行うことができます。これにより、開発者はデータベースとのやり取りをより直感的に行うことができ、コードの可読性と保守性が向上します。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
typeorm3,067,62236,12820.8 MB54012日前MIT
sequelize2,463,07130,2742.91 MB1,0009ヶ月前MIT
objection210,7077,352645 kB1271年前MIT
bookshelf85,5626,365-2376年前MIT
機能比較: typeorm vs sequelize vs objection vs bookshelf

データベースサポート

  • typeorm:

    TypeORMは、リレーショナルデータベース(MySQL、PostgreSQL、SQLiteなど)とNoSQLデータベース(MongoDBなど)の両方をサポートしています。

  • sequelize:

    Sequelizeは、MySQL、PostgreSQL、SQLite、Microsoft SQL Serverなど、非常に多くのデータベースをサポートしています。

  • objection:

    Objection.jsもKnex.jsを基盤にしており、同様にPostgreSQL、MySQL、SQLiteをサポートしていますが、より複雑なクエリに対応しています。

  • bookshelf:

    Bookshelfは、Knex.jsを使用しており、PostgreSQL、MySQL、SQLiteなどの複数のデータベースをサポートしています。

クエリビルダー

  • typeorm:

    TypeORMは、エンティティを使用したクエリビルダーを提供しており、TypeScriptの型安全性を活かしたクエリ作成が可能です。

  • sequelize:

    Sequelizeは、非常に強力なクエリビルダーを持ち、複雑なクエリやトランザクションを簡単に扱うことができます。

  • objection:

    Objection.jsは、Knex.jsのクエリビルダーを使用しており、複雑なクエリを簡単に作成できる強力な機能を提供します。

  • bookshelf:

    Bookshelfはシンプルなクエリビルダーを提供しており、基本的なCRUD操作を簡単に行えますが、複雑なクエリには制限があります。

リレーションシップ管理

  • typeorm:

    TypeORMは、デコレーターを使用してリレーションシップを定義することができ、視覚的にわかりやすい構文を提供します。

  • sequelize:

    Sequelizeは、リレーションシップの定義が非常に柔軟で、複雑なリレーションも簡単に設定できます。

  • objection:

    Objection.jsは、リレーションシップの管理が強化されており、複雑なリレーションを簡単に扱うことができます。

  • bookshelf:

    Bookshelfは、シンプルなリレーションシップ管理機能を提供しており、1対多、多対多のリレーションを簡単に設定できます。

TypeScriptサポート

  • typeorm:

    TypeORMはTypeScriptで書かれており、完全な型安全性を提供し、デコレーターを使用したエンティティの定義が可能です。

  • sequelize:

    SequelizeはTypeScriptのサポートがあり、型定義が充実していますが、設定がやや複雑な場合があります。

  • objection:

    Objection.jsはTypeScriptをサポートしており、型安全性を重視する開発者に向いています。

  • bookshelf:

    BookshelfはTypeScriptのサポートが限定的で、型定義が不足している場合があります。

学習曲線

  • typeorm:

    TypeORMはTypeScriptに特化しているため、TypeScriptに慣れている開発者には学びやすいですが、初めての人には少し難しいかもしれません。

  • sequelize:

    Sequelizeは多機能ですが、設定や使い方が複雑なため、学習曲線はやや急です。

  • objection:

    Objection.jsはBookshelfよりも機能が豊富なため、学習曲線はやや急ですが、強力な機能を活用することができます。

  • bookshelf:

    BookshelfはシンプルなAPIを持っているため、学習曲線は比較的緩やかで、初心者でも扱いやすいです。

選び方: typeorm vs sequelize vs objection vs bookshelf
  • typeorm:

    TypeORMは、TypeScriptで書かれたORMで、エンティティベースのアプローチを採用しています。TypeScriptを使用するプロジェクトや、デコレーターを活用したい開発者に最適です。リレーショナルデータベースとNoSQLデータベースの両方をサポートしており、柔軟性があります。

  • sequelize:

    Sequelizeは、非常に人気のあるORMで、MySQL、PostgreSQL、SQLite、Microsoft SQL Serverなど、複数のデータベースをサポートしています。大規模なアプリケーションや複雑なデータモデルを持つプロジェクトに向いており、豊富な機能と強力なコミュニティサポートがあります。

  • objection:

    Objection.jsは、Bookshelfの上に構築されたORMで、より強力なクエリビルダーを提供します。複雑なクエリやトランザクションが必要な中規模から大規模なプロジェクトに最適です。TypeScriptのサポートもあり、型安全性を重視する開発者に適しています。

  • bookshelf:

    Bookshelfは、Knex.jsをベースにしたシンプルで使いやすいORMです。小規模から中規模のプロジェクトに適しており、シンプルなAPIを好む開発者に向いています。リレーションシップの管理が容易で、柔軟性があります。

typeorm のREADME

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.

Champion

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

Supporter

Support TypeORM's development with a monthly contribution. Become a supporter

Community

Join our community of supporters and help sustain TypeORM. Become a community supporter

Sponsor

Make a one-time or recurring contribution of your choice. Become a sponsor