Back to rankings

typeorm/typeorm

TypeScripttypeorm.io

TypeScript & JavaScript ORM for Node.js — supports PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, and more.

ormtypescriptjavascriptdatabasetypeormmysqlmariadbpostgresqlsqlitesqlserveractive-recorddata-mapper
Star Growth
Stars
36.6k
Forks
6.6k
Weekly Growth
Issues
428
10k20k30k
Aug 2016Nov 2019Mar 2023Jul 2026
Artifactsnpmnpm install 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 (ES2023). 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 as 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

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

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

Related repositories
django/django

The Web framework for perfectionists with deadlines.

PythonPyPIBSD 3-Clause "New" or "Revised" Licensepythondjango
djangoproject.com
88.2k34.1k
prisma/prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

TypeScriptnpmApache License 2.0prismaorm
prisma.io
47.4k2.4k
go-gorm/gorm

The fantastic ORM library for Golang, aims to be developer friendly

GoGo ModulesMIT Licensegogolang
gorm.io
39.9k4.2k
drizzle-team/drizzle-orm

ORM

TypeScriptnpmApache License 2.0typescriptorm
orm.drizzle.team
35.2k1.5k
sequelize/sequelize

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB, DB2 and DB2 for IBM i.

TypeScriptnpmMIT Licensejavascriptsql
sequelize.org
30.4k4.3k
chinabugotech/hutool

🍬A set of tools that keep Java sweet.

JavaMavenMulan Permissive Software License, Version 2javahutool
hutool.cn
30.3k7.6k
dromara/hutool

🍬A set of tools that keep Java sweet.

JavaMavenjavahutool
hutool.cn
29.4k7.5k
Automattic/mongoose

MongoDB object modeling designed to work in an asynchronous environment.

JavaScriptnpmMIT Licensemongomongodb
mongoosejs.com
27.5k4k
sqlc-dev/sqlc

Generate type-safe code from SQL

GoGo ModulesMIT Licensegopostgresql
sqlc.dev
18.1k1.1k
baomidou/mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development

JavaMavenApache License 2.0mybatismybatis-plus
baomidou.com
17.4k4.4k
ent/ent

An entity framework for Go

GoGo ModulesApache License 2.0entorm
entgo.io
17.1k1k
prisma/prisma1

💾 Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]

ScalaApache License 2.0ormdatabase
v1.prisma.io/docs/
16.4k839