My goal is to be able to have a single NestJS to communicate to do different databases on the same cluster. One another team manages (read only) and one we manage (read/write). My understanding is TypeORM can handle this. However I'm not able to get this to to work. It's not able to create or inject the data service into repositories created by NestJS.
In the attached project you will see basic config. In the AppService I'm not injecting the items needed yet. So I think this may be a bug in NestJS OR I need to configure it another way that is different from documentation.
In the mysql folder run docker-compose up -d to start up a mysql instance
This may or may not even be needed because I don't think the app is even connecting yet)
Run yarn start
Expected behavior
I'm expecting to be able to have 2 databases that I can connect to and inject repositories for each as well as being able to use one of the repos (to do a cross database query as mentioned is possible in this Issue: https://github.com/typeorm/typeorm/issues/1196 )
Example for using Repository:
@InjectRepository(UserEntity, 'DsSchemaA') userRepo: Repository,
@InjectRepository(CompanyEntity, 'DsSchemaB') companyRepo: Repository,
Is there an existing issue for this?
Current behavior
My goal is to be able to have a single NestJS to communicate to do different databases on the same cluster. One another team manages (read only) and one we manage (read/write). My understanding is TypeORM can handle this. However I'm not able to get this to to work. It's not able to create or inject the data service into repositories created by NestJS.
In the attached project you will see basic config. In the AppService I'm not injecting the items needed yet. So I think this may be a bug in NestJS OR I need to configure it another way that is different from documentation.
Documentation reference: https://docs.nestjs.com/techniques/database#multiple-databases
Minimum reproduction code
https://github.com/ccaspanello/nestjs-multiple-databases
Steps to reproduce
Checkout repo:
mysql
folder rundocker-compose up -d
to start up a mysql instanceyarn start
Expected behavior
I'm expecting to be able to have 2 databases that I can connect to and inject repositories for each as well as being able to use one of the repos (to do a cross database query as mentioned is possible in this Issue: https://github.com/typeorm/typeorm/issues/1196 )
Example for using Repository: @InjectRepository(UserEntity, 'DsSchemaA') userRepo: Repository,
@InjectRepository(CompanyEntity, 'DsSchemaB') companyRepo: Repository,
Package
Other package
@nestjs/typeorm / @nestjs/config
NestJS version
No response
Packages versions
See attached GitHub Repo for full version
Node.js version
v22.4.1
In which operating systems have you tested?
Other
No response