question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple databases feature repository can not be provided

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, May 12, 2019

Why add this constraint in 6.1, when it did not exist in 6.0 ?

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:

@InjectRepository(Person, 'personsConnection') 
private readonly repo: Repository<Person>,

We’ll update the docs for better clarity. I’m sorry for your inconveniences.

0reactions
kamilmysliwieccommented, Sep 4, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found