typeorm is a free, open source databases project written in TypeScript and released under MIT. It has 36,652 GitHub stars, 6,670 forks and 646 open issues, and was last pushed 7 days ago. On this registry it ranks #10 of 81 tracked projects in Databases, with 5 head-to-head comparisons available.

What is typeorm?

TypeORM is an MIT-licensed object-relational mapper for TypeScript and JavaScript that runs on Node.js, in the browser, and across mobile and desktop platforms, and it is aimed at developers who want to model, query, and migrate SQL and NoSQL databases from one decorator-driven codebase.

What it is

TypeORM is an ORM that runs on Node.js, Browser, Cordova, Ionic, React Native, NativeScript, Expo, and Electron, and it works with TypeScript and JavaScript (ES2023). Its stated goal is to support the latest JavaScript features and to add the features needed by any application that uses databases, from small applications with a few tables to large-scale enterprise applications with multiple databases. The project is heavily influenced by Hibernate, Doctrine, and Entity Framework, and it lives in the Infrastructure & Operations / Databases category with the active-record, data-mapper, database, orm, postgresql, mysql, mariadb, sqlite, sqlserver, and cockroachdb topics.

The concrete problem it solves is the gap between an application's object model and the many databases it may need to talk to. TypeORM replaces hand-written SQL and single-dialect query layers: entities and columns carry database-specific column types, repositories and an entity manager replace ad-hoc queries, an elegant-syntax QueryBuilder replaces string-concatenated SQL, and migrations with automatic migrations generation replace manually maintained schema scripts. Under this sits a driver matrix covering PostgreSQL, MySQL/MariaDB, CockroachDB, SQLite, SQL Server, Oracle, SAP HANA, MongoDB, Google Spanner, and sql.js, so the same domain logic can run against several database types, support cross-database and cross-schema queries, and address multiple database instances from one application.

Key capabilities

  • Supports both the Active Record pattern (BaseEntity) and the Data Mapper pattern (repositories), which the README describes as unlike all other JavaScript ORMs currently in existence.
  • Decorator-based entities and columns, for example @Entity(), @PrimaryGeneratedColumn(), and @Column(), with database-specific column types.
  • An elegant-syntax, flexible and powerful QueryBuilder with left and inner joins and proper pagination for queries using joins.
  • Migrations and automatic migrations generation.
  • Broad database coverage: PostgreSQL, MySQL/MariaDB, CockroachDB, SQLite, Microsoft SQL Server, Oracle, SAP HANA, MongoDB, Google Spanner, and sql.js.
  • Transactions, connection pooling, replication, and use of multiple database instances.
  • A CLI plus listeners and subscribers (hooks), query caching, logging, streaming raw results, indices, cascades, and eager and lazy relations.

Who uses it and how

  • Teams building anything from small applications with a few tables to large-scale enterprise applications with multiple databases.
  • Applications that need several database types at once, using cross-database and cross-schema queries and multiple database instances.
  • Projects that ship across Node.js, Ionic, Cordova, React Native, NativeScript, Expo, Electron, and the browser from shared TypeScript or JavaScript.
  • Codebases that require both ESM and CommonJS output.
  • Developers who need unidirectional, bidirectional, and self-referenced relations, multiple inheritance patterns, and the closure table pattern without hand-writing joins.

Getting started

TypeORM is distributed as the typeorm package; the README imports entities and decorators from it, for example import { Entity, PrimaryGeneratedColumn, Column } from "typeorm", then wires a DataSource before calling MyDataSource.getRepository(User) and repository methods such as save, find, findOneBy, and remove. A CLI is listed among the features, and the project's homepage is at typeorm.io.

How it compares

TypeORM is heavily influenced by Hibernate, Doctrine, and Entity Framework, but it targets TypeScript and JavaScript rather than Java, PHP, or .NET. Its distinguishing position within that lineage is dual support for both the Active Record and Data Mapper patterns, which the README claims no other current JavaScript ORM offers.

When to use it — and when not to

Adopting TypeORM means operating the underlying database yourself: the project connects to PostgreSQL, MySQL, MariaDB, CockroachDB, SQLite, SQL Server, Oracle, SAP HANA, or MongoDB, but it does not run those servers or any other infrastructure for you. Teams that want only a thin query wrapper over a single database, or that want no decorator and entity-metadata layer at all, are likely better served by a smaller tool. The repository currently carries 646 open issues, so a sizeable backlog is the honest trade-off against the 36,651 stars, 6,671 forks, and clear MIT licence.

project readme (upstream, from github) — read inline
TypeORM Logo

NPM Version NPM Downloads Coverage MIT License

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](https://github.com/typeorm/typeorm/blob

readme truncated — read the full docs on github

Frequently asked questions

Is typeorm free to use?

typeorm is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does typeorm do?

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

What is typeorm written in?

typeorm is primarily written in TypeScript. Its source is publicly available at https://github.com/typeorm/typeorm, and it has 36,652 GitHub stars.