🗄️
Database1.5M+/wkMIT

typeorm

TypeORM is a full-featured ORM for TypeScript and JavaScript that supports both Active Record and Data Mapper patterns, working with PostgreSQL, MySQL, MariaDB,

Installation

npm
npm install typeorm
yarn
yarn add typeorm
pnpm
pnpm add typeorm

Import

ESM
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

Quick Example

usage
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column({ unique: true })
  email: string;
}

About typeorm

TypeORM is a full-featured ORM for TypeScript and JavaScript that supports both Active Record and Data Mapper patterns, working with PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, CockroachDB, and MongoDB. TypeORM uses decorators to define entities (database tables), columns, relations, indices, and constraints directly on TypeScript classes, providing a natural mapping between objects and database records. The library supports eager and lazy relations, cascading operations, query builders with complex joins and subqueries, transactions, migrations, subscribers for entity lifecycle events, and connection pooling. TypeORM provides both a repository pattern (EntityManager/Repository) and a query builder for flexible data access. The Active Record pattern lets entities call methods like User.find() directly, while the Data Mapper pattern separates the entity definition from the repository logic. TypeORM integrates tightly with NestJS through @nestjs/typeorm, providing dependency injection for repositories. The migration system generates SQL migrations from entity changes. While Prisma has gained ground for new TypeScript projects, TypeORM remains popular in enterprise applications, particularly those using the decorator-based NestJS pattern.

Quick Facts

Packagetypeorm
CategoryDatabase
Weekly Downloads1.5M+
LicenseMIT
Installnpm install typeorm

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.