{"id":10425,"library":"typeorm","title":"TypeORM","description":"TypeORM is a powerful Data-Mapper ORM designed for TypeScript and ES2021+ applications, providing advanced features for database interaction. It supports a wide array of popular relational and NoSQL databases, including MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, SAP HANA, SQLite, and MongoDB. The current stable version is 0.3.28, with frequent patch and minor releases indicating active development.","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":[],"imports":[{"note":"TypeORM 0.3.x is designed for modern JavaScript environments (ES2021+) and strongly encourages ESM imports.","wrong":"const DataSource = require('typeorm')","symbol":"DataSource","correct":"import { DataSource } from 'typeorm'"}],"quickstart":{"code":"import \"reflect-metadata\";\nimport { DataSource, Entity, PrimaryGeneratedColumn, Column, Repository } from \"typeorm\";\n\n@Entity()\nclass User {\n    @PrimaryGeneratedColumn()\n    id!: number;\n\n    @Column()\n    firstName!: string;\n\n    @Column()\n    lastName!: string;\n}\n\nasync function run() {\n    const AppDataSource = new DataSource({\n        type: \"sqlite\",\n        database: \"database.sqlite\",\n        synchronize: true, // For development, automatically create schema\n        entities: [User],\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 user = new User();\n    user.firstName = \"John\";\n    user.lastName = \"Doe\";\n    await userRepository.save(user);\n    console.log(\"User saved:\", user);\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\nrun().catch(error => console.error(\"Error:\", error));","lang":"typescript","description":"This example demonstrates how to initialize a TypeORM DataSource with SQLite, define a simple User entity, create its schema, and then perform basic save and find operations. It highlights the core steps for getting started with TypeORM in a TypeScript environment."},"warnings":[{"fix":"To delete/update all entities, pass `true` as the criteria (e.g., `repository.delete(true)`).","message":"Calling `repository.delete({})` or `repository.update({}, data)` no longer deletes/updates all rows. Instead, it throws an error to prevent accidental mass deletion/updates.","severity":"breaking","affected_versions":">=0.3.23"},{"fix":"Install `reflect-metadata` (`npm install reflect-metadata`) and add `import \"reflect-metadata\";` at the very top of your main entry file (e.g., `main.ts` or `app.ts`).","message":"The `reflect-metadata` polyfill is required for TypeORM's decorators to work but must be explicitly installed and imported once at the top of your application's entry file.","severity":"gotcha","affected_versions":">=0.3.21"},{"fix":"If you encounter issues or need to revert to the old behavior, set `connectionOptions.extra.stringifyObjects = false` in your data source configuration.","message":"When using MySQL, TypeORM now defaults `connectionOptions.extra.stringifyObjects` to `true` to mitigate a potential security vulnerability in underlying MySQL drivers.","severity":"gotcha","affected_versions":">=0.3.26"},{"fix":"Remove `hdb-pool` from your project dependencies and update your SAP HANA connection configuration to rely on the built-in pooling.","message":"For SAP HANA connections, TypeORM now utilizes the built-in connection pooling from the `@sap/hana-client` library. The external `hdb-pool` library is deprecated.","severity":"deprecated","affected_versions":">=0.3.26"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"If you intend to delete all entities, change the call to `repository.delete(true)`.","cause":"Attempting to delete all entities by calling `repository.delete({})` without explicitly confirming the intent to delete all. This behavior changed in 0.3.23 to prevent accidental mass deletion.","error":"Cannot delete without criteria. Pass 'true' to delete all entities."},{"fix":"Install `reflect-metadata` (`npm install reflect-metadata`) and add `import \"reflect-metadata\";` as the very first line in your application's entry file.","cause":"The `reflect-metadata` polyfill, essential for TypeScript decorators used by TypeORM, has not been installed or imported at the application's entry point.","error":"TypeError: Reflect.decorate is not a function"},{"fix":"Install the correct database driver for your chosen database, e.g., `npm install pg` for PostgreSQL or `npm install mysql2` for MySQL.","cause":"TypeORM requires a specific database driver (e.g., `pg` for PostgreSQL, `mysql2` for MySQL) to be installed as a peer dependency, but it's missing for the configured database type.","error":"No driver for database type \"...\" was found installed. Try to install the corresponding driver for your database."},{"fix":"Ensure your `DataSource` configuration's `entities` array correctly lists your entity classes or provides accurate glob patterns to their location (e.g., `[User, Post]`, `[\"**/*.entity{.ts,.js}\"]`).","cause":"The `entities` array in your `DataSource` configuration is empty, or the glob patterns/paths specified for your entities are incorrect, preventing TypeORM from discovering your entity classes.","error":"No entities were found in the given directory: ..."},{"fix":"Update TypeORM to version `0.3.19` or later, as this issue was resolved in `0.3.19` and confirmed fixed in `0.3.20`.","cause":"This error was a bug in previous versions of TypeORM related to an upgrade of the `glob` package.","error":"Cannot read properties of undefined (reading 'sync')"}],"ecosystem":"npm"}