typeorm-common
Expose some useful TypeORM integrations.
Installation
yarn add -E @codemeistre/typeorm-common
Usage
NestJs
As TypeORM ^0.3.0 do not support custom repositories via @EntityRepository()
, here's a workaround to continue using the same API. This package is based on it.
@CustomRepository(Entity)
Similarly to @EntityRepository()
, it should be used in the repository class.
@CustomRepository(FooEntity)
export class FooRepository extends Repository<FooEntity> {}
CustomRepositoryModule.forFeature([Repositories])
Similarly to @TypeOrmModule.forFeature()
, it should be used in the resource module.
@Module({
imports: [CustomRepositoryModule.forFeature([FooRepository])],
exports: [CustomRepositoryModule],
})
export class FooModule {}
IMPORTANT: As we are not using TypeORmModule.forFeature()
, we must provide the entities manually in entities
when starting the TypeOrmModule
, so autoLoadEntities
won't work!.
@Module({
imports: [
TypeOrmModule.forRoot({
entities: [FooEntity],
}),
],
})
export class DatabaseModule {}