Multiple databases feature repository can not be provided
See original GitHub issueI’m submitting a…
[ ] Regression
[*] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
New Error in 6.1.0 (6.0.0 is ok)
const defaultOptions = {
type: 'postgres',
port: 5432,
username: 'user',
password: 'password',
database: 'db',
synchronize: true,
};
@Module({
imports: [
TypeOrmModule.forRoot({
...defaultOptions,
host: 'photo_db_host',
entities: [Photo],
}),
TypeOrmModule.forRoot({
...defaultOptions,
name: 'personsConnection',
host: 'person_db_host',
entities: [Person],
}),
TypeOrmModule.forRoot({
...defaultOptions,
name: 'albumsConnection',
host: 'album_db_host',
entities: [Album],
}),
],
})
export class ApplicationModule {}
@Module({
imports: [
TypeOrmModule.forFeature([Photo]),
TypeOrmModule.forFeature([Person], 'personsConnection'),
],
providers: [
PhotoService,
PersonService
]
})
export class SubModule {}
@Injectable()
export class PersonService {
constructor(
@InjectRepository(Person) private readonly repo: Repository<Person>,
) {}
}
@Injectable()
export class PhotoService {
constructor(
@InjectRepository(Photo) private readonly repo: Repository<Photo>,
) {}
}
Get error
Nest can't resolve dependencies of the PersonService (?). Please make sure that the argument at index [0] is available in the SubModule context.
Environment
Nest version: 6.1.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Multiple Databases | Nestjs-query - Blog
Multiple Databases. TypeOrm offers the possibility to connect your application to multiple databases or schemas. More details on this can be found on...
Read more >Creating multiple databases in Dolt | DoltHub Blog
This blog post is about how the new feature works, ... dolt sql The current directory is not a valid dolt repository. run:...
Read more >Multiple Databases - GitLab Docs
Because GitLab can be run with multiple separate databases, referencing ci tables with non ci tables in a single query is not possible....
Read more >Perform search operations in multiple Databases in Spring ...
It won't work out-of-the-box. If you include the spring-boot mongodb starter project, it will look for the property ...
Read more >Search Multiple Databases at Once - How to Choose and Use ...
While searching multiple databases at once can be useful, ... This means that all the wonderful advanced features available in each database ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It was a bug. Previously, if you registered 1 entity under 2 connections at the same time, you wouldn’t be able to inject the second one (they would override each other).
@InjectRepository()
uses default connection, unless you specify the connection name as a second parameter. In order to explicitly set the connection name, use construction that I’ve set out above:We’ll update the docs for better clarity. I’m sorry for your inconveniences.
@Napas It’s not a connection detail but rather a token, indicator for which connection you want to use (if you have multiple of them) - which is totally fine.