2017-12-18 2 views
0

연결 클래스를 여기에 provide과 같이 사용할 수 있습니까? 종속성을 찾을 수없는 경우 nestjs에서연결 클래스로 유형 연결

constructor(
    private connection: Connection, 
) { 
    this.repository = connection.getRepository(Project); 
} 

:

import { Connection, createConnection } from 'typeorm'; 

export const databaseProviders = [{ 
    provide: Connection, 
    useFactory: async() => await createConnection({ 
    type: 'postgres', 
    host: 'localhost', 
    port: 5432, 
    username: 'postgres', 
    password: 'postgres', 
    database: 'testo', 
    entities: [ 
     __dirname + '/../**/*.entity{.ts,.js}', 
    ], 
    logging: true, 
    synchronize: true, 
    }), 
}]; 

수입이처럼 작동하게합니다. 나는 문제가 typeorm에있는 것 같아요, 그것은 일반 es5 기능에 컴파일됩니다. 하지만 아마도 이것에 대한 해결책이 있을까요?

repository to reproduce

UPDATE :

나는 허용 솔루션 nestjs typeorm module을 찾았지만, 내 Connection 클래스가 작동되지 않는 이유를 이해하지 않지만, 그것은 문자열을 잘 작동합니다. Hope @ kamil-myśliwiec은 이해하는데 도움이 될 것입니다.

modules: [ 
    TypeOrmModule.forRoot(
     [ 
     Build, 
     Project, 
     ], 
     { 
     type: 'postgres', 
     host: 'localhost', 
     port: 5432, 
     username: 'postgres', 
     password: 'postgres', 
     database: 'testo', 
     entities: [ 
      Build, 
     ], 
     logging: true, 
     synchronize: true, 
     }), 
    ], 
    // And the n inject like this by entity name 
    @InjectRepository(Build) private repository: Repository<Build>, 

답변

1

예, 그렇습니다. 더 많은 코드를 공유 할 수 있습니까?

+0

질문에 repo를 추가하십시오. 괜찮 으면 네스트 문서를'Connection' 클래스로 다시 써야합니다 :) 또한'autoSchemaSync'는'typeorm'에서'synchronize'로 변경되었습니다. –

+0

실제로, 나는 지금 그것에있다 :) –

+0

안녕하세요, 이것에 관한 어떤 뉴스? 내 레포에서 잘못한 일을 했습니까? –