
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Data-Mapper ORM for TypeScript and ES2021+. Supports MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, SAP HANA, SQLite, MongoDB databases.
TypeORM is an Object-Relational Mapper (ORM) for Node.js that can be used with TypeScript or JavaScript (ES5, ES6, ES7, ES8). It supports both Active Record and Data Mapper patterns, unlike other JavaScript ORMs. You can use it with TypeScript and JavaScript (ES5, ES6, ES7, ES8). It's highly influenced by other ORMs, such as Hibernate, Doctrine, and Entity Framework.
Entity Definition
This code sample demonstrates how to define an entity in TypeORM. Entities are the equivalent of tables in a database, and each instance of an entity represents a row in the table.
import {Entity, PrimaryGeneratedColumn, Column} from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
isActive: boolean;
}
CRUD Operations
This code sample shows how to perform CRUD (Create, Read, Update, Delete) operations using the repository API provided by TypeORM.
import {getRepository} from 'typeorm';
import {User} from './entity/User';
async function createUser() {
const userRepository = getRepository(User);
const user = new User();
user.firstName = 'Timber';
user.lastName = 'Saw';
user.isActive = true;
await userRepository.save(user);
}
async function findUserById(id) {
const userRepository = getRepository(User);
return await userRepository.findOne(id);
}
Data Querying
This code sample illustrates how to query data using the QueryBuilder API, which allows for building SQL queries in a programmatic and type-safe manner.
import {getConnection} from 'typeorm';
async function getUsersByName(firstName) {
const users = await getConnection()
.getRepository(User)
.createQueryBuilder('user')
.where('user.firstName = :firstName', { firstName })
.getMany();
return users;
}
Transactions
This code sample demonstrates how to perform transactions, ensuring that all operations within the transaction block either complete successfully together or are all rolled back.
import {getConnection} from 'typeorm';
async function updateUserLastName(id, lastName) {
await getConnection().transaction(async transactionalEntityManager => {
const user = await transactionalEntityManager.findOne(User, id);
user.lastName = lastName;
await transactionalEntityManager.save(user);
});
}
Migrations
This code sample shows how to define a migration class in TypeORM. Migrations are a way to manage database schema changes and can be automatically generated or manually written.
import {MigrationInterface, QueryRunner} from 'typeorm';
export class CreateUserTable1588102412341 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE user (id int PRIMARY KEY, firstName varchar(255), lastName varchar(255))`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('DROP TABLE user');
}
}
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication, and more. Compared to TypeORM, Sequelize has been around for longer and has a larger community, but it doesn't have as strong TypeScript support.
Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features a simple and intuitive API and supports transactions, eager/nested-eager relation loading, and plugins. Unlike TypeORM, Bookshelf follows a more traditional JavaScript style and doesn't emphasize TypeScript integration.
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 (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, Microsoft SqlServer, MySQL/MariaDB, MongoDB, Oracle, Postgres, SAP HANA and SQLite, as well we 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.
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()
Take a look at the samples in sample for examples of usage.
There are a few repositories that you can clone and start with:
There are several extensions that simplify working with TypeORM and integrating it with other modules:
data-source.ts
after generating migrations/entities - typeorm-codebase-syncrelations
objects - typeorm-relationsrelations
based on a GraphQL query - typeorm-relations-graphqlLearn about contribution here and how to set up your development environment here.
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 sponsor
Become a gold sponsor and get premium technical support from our core contributors. Become a gold sponsor
0.3.26 (2025-08-16)
Notes:
stringifyObjects: true
, in order to avoid a potential security vulnerability
in the mysql/mysql2 client libraries. You can revert to the old behavior by setting connectionOptions.extra.stringifyObjects = false
.@sap/hana-client
library. The deprecated hdb-pool
is no longer necessary and can be removed. See https://typeorm.io/docs/drivers/sap/#data-source-options for the new pool options.stringifyObjects
implicitly (#11574) (d57fe3b)useIndex
when cloning a QueryExpressionMap (or a QueryBuilder) (#10679) (66ee307), closes #10678 #10678FAQs
Data-Mapper ORM for TypeScript and ES2021+. Supports MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, SAP HANA, SQLite, MongoDB databases.
The npm package typeorm receives a total of 2,347,601 weekly downloads. As such, typeorm popularity was classified as popular.
We found that typeorm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.