【发布时间】:2022-01-09 16:44:01
【问题描述】:
我通过nestjs docs (custom repository, multiple databases) 编写代码
这是我的代码。
// app.module.ts
@Module({
imports: [
TypeOrmModule.forRoot({
name: 'MYSQL_CONNECTION',
type: 'mysql',
port: 3306,
entities: [AwsTest],
logger: new MysqlLogger(),
synchronize: false,
extra: {
connectionLimit: 10,
},
}),
TypeOrmModule.forRoot({
name: 'ORACLE_CONNECTION',
type: 'oracle',
entities: [],
synchronize: false,
logger: new OracleLogger(),
extra: {
connectionLimit: 10,
},
}),
TestModule,
],
providers: [Logger],
})
export class AppModule implements NestModule {}
// test.module.ts
@Module({
imports: [TypeOrmModule.forFeature([TestRepository], 'MYSQL_CONNECTION')],
providers: [TestService],
controllers: [TestController],
})
export class TestModule {}
// test.service.ts
@Injectable()
export class TestService {
constructor(private readonly testRepository: TestRepository) {}
async getAwsTest() {
return await this.testRepository.getAwsTest()
}
}
// test.repository.ts
@EntityRepository(AwsTest)
export class TestRepository extends BaseRepository<AwsTest> {
async getAwsTest() {
return await this.find()
}
}
// aws-test.entity.ts
@Entity('test', { database: 'report' })
export class AwsTest {
constructor(name: string, address: string) {
this._name = name
this._address = address
}
@Column('varchar', { primary: true, name: 'name' })
readonly _name: string
@Column('varchar', { name: 'address' })
readonly _address: string
}
在这种情况下,嵌套应用程序没有运行。 这是错误控制台。
Nest can't resolve dependencies of the TestService (?). Please make sure that the argument TestRepository at index [0] is available in the TestModule context.
Potential solutions:
If TestRepository is a provider, is it part of the current TestModule?
If TestRepository is exported from a separate @Module, is that module imported within TestModule? @Module({ imports: [ /* the Module containing TestRepository */ ] })
我需要你的帮助.....(在 app.module.ts 中,我制作了不可见的关键信息,如主机、用户名、密码、数据库、sid...)
【问题讨论】:
-
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。