TypeORM is an ORMthat can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platformsand can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8).Its goal is to always support the latest JavaScript features and provide additional featuresthat help you to develop any kind of application that uses databases - fromsmall applications with a few tables to large scale enterprise applicationswith multiple databases.

    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 the most productive way.

    TypeORM is highly influenced by other ORMs, such as Hibernate, Doctrine and Entity Framework.

    Some TypeORM 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
    • uni-directional, bi-directional and self-referenced relations
    • supports multiple inheritance patterns
    • cascades
    • indices
    • transactions
    • migrations and automatic migrations generation
    • connection pooling
    • replication
    • using multiple database connections
    • working with multiple databases 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
    • connection configuration in json / xml / yml / env formats
    • supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / Oracle / sql.js
    • supports MongoDB NoSQL database
    • works in NodeJS / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms
    • TypeScript and JavaScript support
    • produced code is performant, flexible, clean and maintainable
    • follows all possible best practices
    • CLI

    And more…

    With TypeORM your models look like this:

    1. import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
    2. @Entity()
    3. export class User {
    4. @PrimaryGeneratedColumn()
    5. id: number;
    6. @Column()
    7. firstName: string;
    8. @Column()
    9. lastName: string;
    10. @Column()
    11. age: number;
    12. }

    And your domain logic looks like this:

    1. const user = new User();
    2. user.firstName = "Timber";
    3. user.lastName = "Saw";
    4. user.age = 25;
    5. await repository.save(user);
    6. const allUsers = await repository.find();
    7. const firstUser = await repository.findOne(1); // find by id
    8. const timber = await repository.findOne({ firstName: "Timber", lastName: "Saw" });
    9. await repository.remove(timber);

    Alternatively, if you prefer to use the ActiveRecord implementation, you can use it as well:

    1. import {Entity, PrimaryGeneratedColumn, Column, BaseEntity} from "typeorm";
    2. @Entity()
    3. export class User extends BaseEntity {
    4. @PrimaryGeneratedColumn()
    5. id: number;
    6. @Column()
    7. firstName: string;
    8. @Column()
    9. lastName: string;
    10. @Column()
    11. age: number;
    12. }

    And your domain logic will look this way:

    1. const user = new User();
    2. user.firstName = "Timber";
    3. user.lastName = "Saw";
    4. user.age = 25;
    5. await user.save();
    6. const allUsers = await User.find();
    7. const firstUser = await User.findOne(1);
    8. const timber = await User.findOne({ firstName: "Timber", lastName: "Saw" });
    9. await timber.remove();