1
votes

I want to make a provider which queries an entity from db. (what interests me actually is to make typeorm available when I create a provider). I get

[ExceptionHandler] Connection "default" was not found. - {"trace":"ConnectionNotFoundError: Connection \"default\" was not found.\n

I tried using service, using custom repository, nothing works. I have something like this in module:

{
      provide: MICROSERVICE_ID,
      useFactory: async (): Promise<Microservice> => {
        //ignore logic
        return await getRepository(Microservice).findOne(1);
      },
      inject: []
    }

TypeOrm is imported on app.module.ts

TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => (configService.get('database'))
    }),

Any help is appreciated.

2

2 Answers

0
votes

Check your database file. The Entity may not load as expected. For newest NestJS version. We should load from ./dist/

0
votes

Fixed by injecting Connection from typeorm.

import { getRepository, Connection } from 'typeorm';
{
      provide: MICROSERVICE_ID,
      useFactory: async (): Promise<Microservice> => {
        //ignore logic
        return await getRepository(Microservice).findOne(1);
      },
      inject: [Connection]
    }