# TypeORM **Repository Path**: mirrors/TypeORM ## Basic Information - **Project Name**: TypeORM - **Description**: TypeORM 是一个优秀的 Node.js ORM 框架,采用 TypeScript 编写,支持使用 TypeScript 或 Javascript(ES5,ES6,ES7) 开 - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: master - **Homepage**: https://www.oschina.net/p/typeorm - **GVP Project**: No ## Statistics - **Stars**: 43 - **Forks**: 16 - **Created**: 2018-03-27 - **Last Updated**: 2025-11-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
TypeORM is an [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping) 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](./docs/docs/drivers/google-spanner.md), [Microsoft SqlServer](./docs/docs/drivers/microsoft-sqlserver.md), [MySQL/MariaDB](./docs/docs/drivers/mysql.md), [MongoDB](./docs/docs/drivers/mongodb.md), [Oracle](./docs/docs/drivers/oracle.md), [Postgres](./docs/docs/drivers/postgres.md), [SAP HANA](./docs/docs/drivers/sap.md) and [SQLite](./docs/docs/drivers/sqlite.md), as well we derived databases and different drivers. TypeORM supports both [Active Record](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-active-record-pattern) and [Data Mapper](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-data-mapper-pattern) 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](http://hibernate.org/orm/), [Doctrine](http://www.doctrine-project.org/) and [Entity Framework](https://www.asp.net/entity-framework). ## Features - Supports both [DataMapper](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-data-mapper-pattern) and [ActiveRecord](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-active-record-pattern) (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: ```typescript 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: ```typescript 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: ```typescript 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: ```typescript 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](https://github.com/typeorm/typeorm/tree/master/sample) for examples of usage. There are a few repositories that you can clone and start with: - [Example how to use TypeORM with TypeScript](https://github.com/typeorm/typescript-example) - [Example how to use TypeORM with JavaScript](https://github.com/typeorm/javascript-example) - [Example how to use TypeORM with JavaScript and Babel](https://github.com/typeorm/babel-example) - [Example how to use TypeORM with TypeScript and SystemJS in Browser](https://github.com/typeorm/browser-example) - [Example how to use TypeORM with TypeScript and React in Browser](https://github.com/ItayGarin/typeorm-react-swc) - [Example how to use Express and TypeORM](https://github.com/typeorm/typescript-express-example) - [Example how to use Koa and TypeORM](https://github.com/typeorm/typescript-koa-example) - [Example how to use TypeORM with MongoDB](https://github.com/typeorm/mongo-typescript-example) - [Example how to use TypeORM in a Cordova app](https://github.com/typeorm/cordova-example) - [Example how to use TypeORM with an Ionic app](https://github.com/typeorm/ionic-example) - [Example how to use TypeORM with React Native](https://github.com/typeorm/react-native-example) - [Example how to use TypeORM with Nativescript-Vue](https://github.com/typeorm/nativescript-vue-typeorm-sample) - [Example how to use TypeORM with Nativescript-Angular](https://github.com/betov18x/nativescript-angular-typeorm-example) - [Example how to use TypeORM with Electron using JavaScript](https://github.com/typeorm/electron-javascript-example) - [Example how to use TypeORM with Electron using TypeScript](https://github.com/typeorm/electron-typescript-example) ## Extensions There are several extensions that simplify working with TypeORM and integrating it with other modules: - [TypeORM integration](https://github.com/typeorm/typeorm-typedi-extensions) with [TypeDI](https://github.com/pleerock/typedi) - [TypeORM integration](https://github.com/typeorm/typeorm-routing-controllers-extensions) with [routing-controllers](https://github.com/pleerock/routing-controllers) - Models generation from the existing database - [typeorm-model-generator](https://github.com/Kononnable/typeorm-model-generator) - Fixtures loader - [typeorm-fixtures-cli](https://github.com/RobinCK/typeorm-fixtures) - ER Diagram generator - [typeorm-uml](https://github.com/eugene-manuilov/typeorm-uml/) - another ER Diagram generator - [erdia](https://www.npmjs.com/package/erdia/) - Create, drop and seed database - [typeorm-extension](https://github.com/tada5hi/typeorm-extension) - Automatically update `data-source.ts` after generating migrations/entities - [typeorm-codebase-sync](https://www.npmjs.com/package/typeorm-codebase-sync) - Easy manipulation of `relations` objects - [typeorm-relations](https://npmjs.com/package/typeorm-relations) - Automatically generate `relations` based on a GraphQL query - [typeorm-relations-graphql](https://npmjs.com/package/typeorm-relations-graphql) - Generate TypeORM entities from Valibot schemas - [piying-orm](https://github.com/piying-org/piying-orm) ## Contributing Learn about contribution [here](https://github.com/typeorm/typeorm/blob/master/CONTRIBUTING.md) and how to set up your development environment [here](https://github.com/typeorm/typeorm/blob/master/DEVELOPER.md). This project exists thanks to all the people who contribute: