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.
npm install typeormVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a SQLite DataSource, defining a User entity with decorators, saving a new user, and fetching all users.
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.Add `import 'reflect-metadata';` as the first line in your main application file (e.g., `main.ts` or `index.ts`).
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.
Remove `hdb-pool` from your project dependencies and update your connection configuration to rely on the `@sap/hana-client` internal pooling.
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.
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.
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.
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.
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.