Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork6.5k
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
License
typeorm/typeorm
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TypeORM is anORM 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 andSQLite, as well we derived databases and different drivers.
TypeORM supports bothActive Record andData 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 asHibernate,Doctrine andEntity Framework.
- Supports bothDataMapper andActiveRecord (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()exportclassUser{ @PrimaryGeneratedColumn()id:number @Column()firstName:string @Column()lastName:string @Column()age:number}
And your domain logic looks like this:
constuserRepository=MyDataSource.getRepository(User)constuser=newUser()user.firstName="Timber"user.lastName="Saw"user.age=25awaituserRepository.save(user)constallUsers=awaituserRepository.find()constfirstUser=awaituserRepository.findOneBy({id:1,})// find by idconsttimber=awaituserRepository.findOneBy({firstName:"Timber",lastName:"Saw",})// find by firstName and lastNameawaituserRepository.remove(timber)
Alternatively, if you prefer to use theActiveRecord implementation, you can use it as well:
import{Entity,PrimaryGeneratedColumn,Column,BaseEntity}from"typeorm"@Entity()exportclassUserextendsBaseEntity{ @PrimaryGeneratedColumn()id:number @Column()firstName:string @Column()lastName:string @Column()age:number}
And your domain logic will look this way:
constuser=newUser()user.firstName="Timber"user.lastName="Saw"user.age=25awaituser.save()constallUsers=awaitUser.find()constfirstUser=awaitUser.findOneBy({id:1,})consttimber=awaitUser.findOneBy({firstName:"Timber",lastName:"Saw",})awaittimber.remove()
Take a look at the samples insample for examples of usage.
There are a few repositories that you can clone and start with:
- Example how to use TypeORM with TypeScript
- Example how to use TypeORM with JavaScript
- Example how to use TypeORM with JavaScript and Babel
- Example how to use TypeORM with TypeScript and SystemJS in Browser
- Example how to use TypeORM with TypeScript and React in Browser
- Example how to use Express and TypeORM
- Example how to use Koa and TypeORM
- Example how to use TypeORM with MongoDB
- Example how to use TypeORM in a Cordova app
- Example how to use TypeORM with an Ionic app
- Example how to use TypeORM with React Native
- Example how to use TypeORM with Nativescript-Vue
- Example how to use TypeORM with Nativescript-Angular
- Example how to use TypeORM with Electron using JavaScript
- Example how to use TypeORM with Electron using TypeScript
There are several extensions that simplify working with TypeORM and integrating it with other modules:
- TypeORM integration withTypeDI
- TypeORM integration withrouting-controllers
- Models generation from the existing database -typeorm-model-generator
- Fixtures loader -typeorm-fixtures-cli
- ER Diagram generator -typeorm-uml
- another ER Diagram generator -erdia
- Create, drop and seed database -typeorm-extension
- Automatically update
data-source.tsafter generating migrations/entities -typeorm-codebase-sync - Easy manipulation of
relationsobjects -typeorm-relations - Automatically generate
relationsbased on a GraphQL query -typeorm-relations-graphql - Generate TypeORM entities from Valibot schemas -piying-orm
Learn about contributionhere and how to set up your development environmenthere.
This project exists thanks to all the people who contribute:
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.
Become a champion sponsor and get premium technical support from our core contributors.Become a champion
Support TypeORM's development with a monthly contribution.Become a supporter
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
About
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Topics
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Contributors1,136
Uh oh!
There was an error while loading.Please reload this page.
