{"id":10425,"library":"typeorm","title":"TypeORM","description":"TypeORM is a highly capable Data-Mapper ORM for TypeScript and ES2021+ applications, providing robust features for interacting with a wide range of databases including MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, SAP HANA, SQLite, and MongoDB. The project is under active development, with its current stable version being 0.3.28 and frequent patch releases. TypeORM distinguishes itself through deep TypeScript integration, allowing developers to define entities using decorators and leverage compile-time type safety throughout the data layer. Its data-mapper pattern offers granular control over database interactions, supporting complex relationships, migrations, and custom repositories, making it a powerful alternative to active record ORMs. It requires Node.js >= 16.13.0 and relies on specific database drivers as peer dependencies.","status":"active","version":"0.3.28","language":"javascript","source_language":"en","source_url":"https://github.com/typeorm/typeorm","tags":["javascript","typescript"],"install":[{"cmd":"npm install typeorm","lang":"bash","label":"npm"},{"cmd":"yarn add typeorm","lang":"bash","label":"yarn"},{"cmd":"pnpm add typeorm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for decorator support in TypeScript. Must be imported once at the application entry point.","package":"reflect-metadata","optional":false},{"reason":"Required for PostgreSQL database support.","package":"pg","optional":true},{"reason":"Required for MySQL/MariaDB database support.","package":"mysql2","optional":true},{"reason":"Required for MongoDB database support.","package":"mongodb","optional":true},{"reason":"Required for SQLite database support.","package":"sqlite3","optional":true},{"reason":"Alternative driver for SQLite, often preferred for performance.","package":"better-sqlite3","optional":true}],"imports":[{"note":"DataSource is the primary class for establishing and managing database connections since v0.3.x. Prefer it over createConnection.","wrong":"const DataSource = require('typeorm').DataSource;","symbol":"DataSource","correct":"import { DataSource } from 'typeorm';"},{"note":"Commonly imported decorators and classes for defining database entities and interacting with them.","wrong":"import { Entity } from 'typeorm/decorator/Entity';","symbol":"Entity","correct":"import { Entity, PrimaryGeneratedColumn, Column, Repository } from 'typeorm';"},{"note":"This import must be placed once at the very top of your application's entry file to enable TypeScript decorators. It provides a polyfill.","symbol":"reflect-metadata","correct":"import 'reflect-metadata';"}],"quickstart":{"code":"import 'reflect-metadata';\nimport { DataSource, Entity, PrimaryGeneratedColumn, Column, Repository } from 'typeorm';\n\n@Entity()\nexport class User {\n  @PrimaryGeneratedColumn()\n  id!: number;\n\n  @Column()\n  firstName!: string;\n\n  @Column()\n  lastName!: string;\n\n  @Column()\n  age!: number;\n}\n\nasync function bootstrap() {\n  const AppDataSource = new DataSource({\n    type: 'sqlite',\n    database: 'database.sqlite',\n    entities: [User],\n    synchronize: true,\n    logging: false,\n  });\n\n  await AppDataSource.initialize();\n  console.log('Data Source has been initialized!');\n\n  const userRepository: Repository<User> = AppDataSource.getRepository(User);\n\n  const newUser = new User();\n  newUser.firstName = 'John';\n  newUser.lastName = 'Doe';\n  newUser.age = 30;\n\n  await userRepository.save(newUser);\n  console.log('User saved:', newUser);\n\n  const allUsers = await userRepository.find();\n  console.log('All users:', allUsers);\n\n  await AppDataSource.destroy();\n  console.log('Data Source has been destroyed.');\n}\n\nbootstrap().catch(error => console.error(error));","lang":"typescript","description":"Demonstrates initializing a SQLite DataSource, defining a User entity with decorators, saving a new user, and fetching all users."},"warnings":[{"fix":"Explicitly define a WHERE clause for delete/update operations (e.g., `repository.delete({ id: Not(IsNull()) })`) or use `createQueryBuilder().delete().execute()` for full table operations.","message":"The `delete({})` and `update({}, { ... })` methods on `EntityManager` and `Repository` APIs no longer delete or update all rows when an empty object is provided as criteria. Instead, they will now throw an error.","severity":"breaking","affected_versions":">=0.3.23"},{"fix":"Add `import 'reflect-metadata';` as the first line in your main application file (e.g., `main.ts` or `index.ts`).","message":"`reflect-metadata` is a peer dependency and must be imported once at the very top of your application's entry point to enable TypeScript decorator metadata. Forgetting this will lead to errors like 'No metadata for X entity was found'.","severity":"gotcha","affected_versions":">=0.3.21"},{"fix":"If you relied on the old behavior, you can revert it by explicitly setting `connectionOptions.extra.stringifyObjects = false` in your `DataSource` configuration. Review object serialization behavior carefully.","message":"When using MySQL, TypeORM now defaults `connectionOptions.extra.stringifyObjects` to `true` to mitigate a potential security vulnerability in the underlying `mysql` / `mysql2` client libraries. This can change how objects are serialized.","severity":"breaking","affected_versions":">=0.3.26"},{"fix":"Remove `hdb-pool` from your project dependencies and update your connection configuration to rely on the `@sap/hana-client` internal pooling.","message":"For SAP HANA connections, TypeORM now utilizes the built-in connection pool of the `@sap/hana-client` library. The `hdb-pool` library is no longer necessary and should be removed from your project.","severity":"breaking","affected_versions":">=0.3.26"},{"fix":"Ensure your TypeScript `tsconfig.json` `module` option is compatible with your runtime environment (e.g., `CommonJS` for Node.js, `ESNext` for bundlers) or configure your build system to correctly transpile TypeORM dependencies.","message":"TypeORM uses CommonJS modules internally in some cases or might cause issues when used in projects with `\"type\": \"module\"` in `package.json` leading to 'Cannot use import statement outside a module' errors.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"search_vec":"'0.3.28':51 '16.13.0':111 'activ':43,105 'allow':63 'altern':103 'applic':15 'capabl':6 'compil':73 'compile-tim':72 'complex':93 'control':88 'current':47 'custom':97 'data':8,79,83 'data-mapp':7,82 'databas':26,90,116 'decor':69 'deep':60 'defin':66 'depend':120 'develop':44,64 'distinguish':57 'driver':117 'entiti':67 'es2021':14 'featur':18 'frequent':53 'granular':87 'hana':35 'high':5 'includ':27 'integr':62 'interact':20,91 'javascript':121 'layer':80 'leverag':71 'make':99 'mapper':9,84 'migrat':95 'mongodb':38 'ms':30 'mysql/mariadb':28 'node.js':110 'offer':86 'oracl':33 'orm':10,107 'patch':54 'pattern':85 'peer':119 'postgresql':29 'power':102 'project':40 'provid':16 'rang':24 'record':106 'relationship':94 'releas':55 'reli':113 'repositori':98 'requir':109 'robust':17 'safeti':76 'sap':34 'server':32 'specif':115 'sql':31 'sqlite':36 'stabl':48 'support':92 'throughout':77 'time':74 'type':75 'typeorm':1,2,56 'typescript':12,61,122 'use':68 'version':49 'wide':23","created_at":"2026-04-18T08:58:43.830335+00:00","updated_at":"2026-04-19T06:06:24.234279+00:00","problems":[{"fix":"Ensure `import 'reflect-metadata';` is the very first line in your application's entry file. Also, verify that your entities array in `DataSource` configuration correctly lists your entity classes or glob patterns.","cause":"The `reflect-metadata` polyfill was not imported or your entity file was not correctly registered with the DataSource.","error":"Error: No metadata for \"YourEntityName\" entity was found."},{"fix":"Always call `AppDataSource.initialize()` and `await` its result before performing any database operations. Check your `DataSource` configuration for the correct `name` if you're using multiple connections.","cause":"The `DataSource` was not correctly initialized with `await AppDataSource.initialize()` before attempting to use it, or you're trying to get a connection by a name that doesn't exist.","error":"TypeORMError: Connection \"default\" was not found."},{"fix":"If using Node.js with ES modules, set `\"type\": \"module\"` in your `package.json` and use `import` statements. If using CommonJS, ensure your `tsconfig.json` outputs `CommonJS` and use `require()` where appropriate, or transpile your code before running.","cause":"Mixing CommonJS `require()` and ES module `import` syntax, or running an ES module (`.ts` / `.mjs`) directly with Node.js without proper configuration (e.g., `\"type\": \"module\"` in `package.json`).","error":"Cannot use import statement outside a module"},{"fix":"Before inserting or updating, check if an entry with the conflicting unique value already exists. Handle the error gracefully or use `upsert` functionality if applicable.","cause":"Attempting to insert or update data that violates a unique constraint defined on a database column, e.g., trying to insert a user with an email that already exists if the email column is unique.","error":"QueryFailedError: SQLITE_CONSTRAINT: UNIQUE constraint failed: entity.column"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"typeorm","cli_version":null,"type":"library","homepage":"https://typeorm.io","github":"https://github.com/typeorm/typeorm","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/typeorm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}