MCPcopy
hub / github.com/typeorm/typeorm

github.com/typeorm/typeorm @1.0.0 sqlite

repository ↗ · DeepWiki ↗ · release 1.0.0 ↗
8,922 symbols 31,865 edges 3,552 files 2,276 documented · 26%
README

    <img height="80" width="auto" alt="TypeORM Logo" src="https://github.com/typeorm/typeorm/raw/master/resources/typeorm-logo-colored-dark.png">

<a href="https://www.npmjs.com/package/typeorm"><img src="https://img.shields.io/npm/v/typeorm" alt="NPM Version"/></a>
<a href="https://www.npmjs.com/package/typeorm"><img src="https://img.shields.io/npm/dm/typeorm" alt="NPM Downloads"/></a>
<a href="https://github.com/typeorm/typeorm/actions/workflows/tests.yml?query=branch%3Amaster"><img src="https://github.com/typeorm/typeorm/actions/workflows/tests.yml/badge.svg?branch=master" alt="Commit Validation"/></a>
<a href="https://sonarcloud.io/summary/overall?id=typeorm_typeorm"><img src="https://sonarcloud.io/api/project_badges/measure?project=typeorm_typeorm&metric=coverage" alt="Coverage"/></a>
<a href='https://dashboard.stryker-mutator.io/reports/github.com/typeorm/typeorm/master'><img src='https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Ftypeorm%2Ftypeorm%2Fmaster' alt='Mutation testing badge' /></a>
<a href=""><img src="https://img.shields.io/badge/License-MIT-teal.svg" alt="MIT License"/></a>

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

Sponsor

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

Extension points exported contracts — how you extend this code

QueryResultCache (Interface)
(no doc) [6 implementers]
src/cache/QueryResultCache.ts
ValueTransformer (Interface)
(no doc) [15 implementers]
src/decorator/options/ValueTransformer.ts
Logger (Interface)
(no doc) [6 implementers]
src/logger/Logger.ts
WhereExpressionBuilder (Interface)
(no doc) [8 implementers]
src/query-builder/WhereExpressionBuilder.ts
EntitySubscriberInterface (Interface)
(no doc) [14 implementers]
src/subscriber/EntitySubscriberInterface.ts
NamingStrategyInterface (Interface)
(no doc) [7 implementers]
src/naming-strategy/NamingStrategyInterface.ts
Driver (Interface)
(no doc) [20 implementers]
src/driver/Driver.ts
QueryRunner (Interface)
(no doc) [11 implementers]
src/query-runner/QueryRunner.ts

Core symbols most depended-on inside this repo

save
called by 3642
src/repository/BaseEntity.ts
Column
called by 2923
src/decorator/columns/Column.ts
getRepository
called by 1409
src/repository/BaseEntity.ts
Entity
called by 1372
src/decorator/entity/Entity.ts
find
called by 1227
src/repository/BaseEntity.ts
createQueryBuilder
called by 1209
src/repository/BaseEntity.ts
findColumnByName
called by 1172
src/schema-builder/table/Table.ts
createTestingConnections
called by 994
test/utils/test-utils.ts

Shape

Class 4,532
Method 3,091
Function 874
Interface 365
Enum 60

Languages

TypeScript100%

Modules by API surface

src/driver/mongodb/typings.ts383 symbols
src/driver/mongodb/MongoQueryRunner.ts106 symbols
src/driver/postgres/PostgresQueryRunner.ts102 symbols
src/driver/cockroachdb/CockroachQueryRunner.ts93 symbols
src/query-builder/SelectQueryBuilder.ts91 symbols
src/driver/sqlserver/SqlServerQueryRunner.ts87 symbols
src/driver/sap/SapQueryRunner.ts85 symbols
src/driver/spanner/SpannerQueryRunner.ts83 symbols
src/driver/oracle/OracleQueryRunner.ts80 symbols
src/driver/mysql/MysqlQueryRunner.ts78 symbols
src/driver/aurora-mysql/AuroraMysqlQueryRunner.ts77 symbols
src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts75 symbols

Dependencies from manifests, versioned

@docusaurus/core3.10.1 · 1×
@docusaurus/module-type-aliases3.10.1 · 1×
@docusaurus/plugin-client-redirects3.10.1 · 1×
@docusaurus/preset-classic3.10.1 · 1×
@docusaurus/tsconfig3.10.1 · 1×
@docusaurus/types3.10.1 · 1×
@eslint/js10.0.1 · 1×
@google-cloud/spanner8.7.1 · 1×
@mdx-js/react3.1.1 · 1×
@sap/hana-client2.28.20 · 1×
@signalwire/docusaurus-plugin-llms-txt1.2.2 · 1×
@sqltools/formatter1.2.5 · 1×

Datastores touched

(mongodb)Database · 1 repos
(mysql)Database · 1 repos
myDatabaseDatabase · 1 repos
testdbDatabase · 1 repos

For agents

$ claude mcp add typeorm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact