TypeORM Adapter
Relevant source files
The following files were used as context for generating this wiki page:
The TypeORM Adapter, provided by the @ptc-org/nestjs-query-typeorm package, implements persistence services for the nestjs-query framework using TypeORM. It translates generic queries into TypeORM-specific operations, enabling CRUD functionality for GraphQL and REST endpoints. This adapter integrates with @ptc-org/nestjs-query-core to provide a consistent interface for data access across different database technologies.
Sources: packages/query-typeorm/package.json:3-5, README.md:31-36
Architecture and Integration
The TypeORM adapter functions as a bridge between the core query logic and the TypeORM library. It uses the NestjsQueryTypeOrmModule to register entities and automatically generate query services.
Component Relationship
The following diagram illustrates how the TypeORM adapter fits into the broader nestjs-query ecosystem.
The adapter implements interfaces defined in the core package to ensure compatibility with GraphQL and REST resolvers.
Sources: packages/core/README.md:14-16, packages/query-typeorm/README.md:12-14
Key Features
The adapter supports several advanced TypeORM and NestJS features to manage complex data requirements.
| Feature | Description |
|---|---|
| Code First CRUD | Automatically generates GraphQL CRUD endpoints based on TypeORM entities. |
| Soft Delete | Manages records that are marked as deleted without being removed from the database. |
| Multiple Databases | Supports connections to multiple database instances within a single application. |
| Custom Services | Allows developers to extend the base TypeORM query service for specialized logic. |
Sources: documentation/sidebars.js:23-29, packages/query-typeorm/README.md:12-13
Module Configuration
The adapter requires peer dependencies to function within a NestJS environment. It specifically depends on @nestjs/common, @nestjs/typeorm, and typeorm.
Dependency Specification
"peerDependencies": {
"@nestjs/common": "^10.0.0 || ^11.0.0",
"@nestjs/typeorm": "^10.0.0 || ^11.0.0",
"class-transformer": "^0.5",
"typeorm": "^0.3.15 || ^1.0.0"
}
Sources: packages/query-typeorm/package.json:33-38
Development and Testing
The TypeORM adapter is part of a monorepo structure managed by Nx and Yarn workspaces.
Implementation Flow
When a request arrives at a resolver, the TypeORM adapter processes the query through the following sequence:
Sources: README.md:14-17, AGENTS.md:7-11
End-to-End Testing
The project includes specific E2E examples for TypeORM integration, including:
basic: Standard TypeORM integration.typeorm-multidb: Testing across different database connections.typeorm-soft-delete: Validating soft-deletion logic.
Sources: examples/nest-cli.json:173-195
Conclusion
The TypeORM adapter simplifies the implementation of data persistence in NestJS applications by automating the creation of services that bridge the gap between TypeORM entities and nestjs-query consumers. By leveraging standard TypeORM patterns, it provides a robust and extensible foundation for building scalable CRUD APIs.