You need to provide some classes and decorators yourself to maintain the same style as typeorm@2.x
.
@EntityRepository(UserEntity)
export class UserRepository extends Repository<UserEntity> {}
↓
@CustomRepository(UserEntity)
export class UserRepository extends Repository<UserEntity> {}
@Module({
exports: [UserService],
imports: [TypeOrmModule.forFeature([UserRepository])],
providers: [UserService],
})
export class UserModule {}
↓
@Module({
exports: [UserService],
imports: [TypeOrmExModule.forCustomRepository([UserRepository])],
providers: [UserService],
})
export class UserModule {}
Thank you for this solution for managing custom repos.
I have custom repositories and entities in a library, that I install using npm.
Datasources are defined in the client project, so from the client I name the DataSource, and use the name as parameter of TypeOrmExModule.forCustomRepository.
But I get an error saying
Nest can't resolve dependencies of the MyEntityRepository (?). Please make sure that the argument DataSource at index [0] is available in the TypeOrmExModule context.
This
MyEntityRepository
does not exist, butMyEntity
andMyRepository
do.Is there a way to fix this?
I tried to add
DataSource
to list of providers, but then I get:TypeError: Cannot read properties of undefined (reading 'name') at new DataSource (D:\xxx\src\data-source\DataSource.ts:133:29) at Injector.instantiateClass (D:\xxx\node_modules\@nestjs\core\injector\injector.js:340:19) at callback (D:\xxx\node_modules\@nestjs\core\injector\injector.js:53:45) at Injector.resolveConstructorParams (D:\xxx\node_modules\@nestjs\core\injector\injector.js:132:24) at Injector.loadInstance (D:\xxx\node_modules\@nestjs\core\injector\injector.js:57:13) at Injector.loadProvider (D:\xxx\node_modules\@nestjs\core\injector\injector.js:84:9) at async Promise.all (index 3) at InstanceLoader.createInstancesOfProviders (D:\xxx\node_modules\@nestjs\core\injector\instance-loader.js:47:9) at D:\xxx\node_modules\@nestjs\core\injector\instance-loader.js:32:13 at async Promise.all (index 6)
Thanks a lot.