NestJS TypeORM
Official TypeORM integration module for NestJS applications
Repository Health
Technical Analysis
@nestjs/typeorm is the official NestJS wrapper around TypeORM, wiring TypeORM’s DataSource and repository pattern into Nest’s dependency-injection container. Instead of manually instantiating a data source and repositories, applications register connections declaratively through TypeOrmModule.forRoot()/forRootAsync() and inject entity repositories into providers with the @InjectRepository() decorator.
The module supports multiple named data sources in a single application, async configuration (for pulling connection options from a ConfigService or secrets manager), and custom repository classes, while staying a thin adapter over TypeORM itself rather than reimplementing any of its query or migration behavior.
What You Get
TypeOrmModule.forRoot()/forRootAsync()for synchronous or async (factory-based) data source configurationTypeOrmModule.forFeature()to register entities per-feature-module and inject their repositories@InjectRepository()and@InjectDataSource()decorators for constructor-based injection into services- Support for multiple named data sources within a single application
- Custom repository support via TypeORM’s
Repositoryextension pattern - An E2E test suite exercising real Postgres/MySQL connections via docker-compose, documenting supported behavior
Common Use Cases
- Standard Nest REST/GraphQL APIs that need a relational database layer wired through DI
- Multi-tenant or multi-database Nest applications registering several named data sources
- Apps that load DB credentials from a
ConfigServiceor secrets manager viaforRootAsync - Modular Nest codebases where each feature module registers only the entities it owns via
forFeature
Under The Hood
Architecture - The module centers on TypeOrmCoreModule (lib/typeorm-core.module.ts), a dynamic module created once via forRoot/forRootAsync that owns the DataSource instance and exposes it as a provider; TypeOrmModule.forFeature() (lib/typeorm.module.ts) then generates per-entity repository providers via createTypeOrmProviders (lib/typeorm.providers.ts) and registers them against a named data source tracked in data-source-name.registry.ts. EntitiesMetadataStorage (lib/entities-metadata.storage.ts) tracks which entities belong to which data source, enabling the multi-connection support, while dedicated exception classes (circular-dependency.exception.ts, duplicate-data-source.exception.ts) give descriptive errors for common misconfigurations rather than opaque DI failures.
Tech Stack - Pure TypeScript targeting the NestJS 11.x provider/module APIs (@nestjs/common, @nestjs/core as peer/dev dependencies) and TypeORM as the underlying ORM; builds via tsc, lints with oxlint, and formats with Prettier. Tests run on Vitest sequentially against real Postgres and MySQL instances spun up through the repo’s docker-compose.yml, and releases are cut with release-it behind Husky/commitlint-enforced Angular-style commit messages.
Code Quality - Nine e2e spec files under tests/e2e exercise real database round-trips (entity registration, repository injection, multiple data sources) rather than mocking TypeORM, which is a stronger quality signal for an integration layer than unit tests alone would be. The lib/ modules are small and single-responsibility (constants, providers, storage, exceptions each isolated), and public APIs are annotated with @publicApi JSDoc tags for documentation tooling.
API Design - The decorator-based API (@InjectRepository(), @InjectDataSource()) mirrors idiomatic Nest DI so existing Nest developers need no new mental model, and forRootAsync supports the standard Nest async-provider shape (useFactory/inject) for config-driven setups. The surface area is intentionally minimal — three static module methods plus two decorators — keeping boilerplate low for a data-access integration.
Used by 6 apps in this directory
APITable
Low Code Platforms · Databases
API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.
Hexabot
AI Development · Automation
Build and run agentic workflows across channels with YAML, tools, and RAG
Laudspeaker
Marketing · Automation
Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.
Swetrix
Analytics
Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.
ToolJet
Low Code Platforms · No Code Platforms · AI Agents
Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.
twenty
CRM
The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.