Skip to content

Commit

Permalink
Merge pull request nestjs#611 from mayorandrew/mention-typeorm-exports
Browse files Browse the repository at this point in the history
content(database) mention exporting repository providers
  • Loading branch information
kamilmysliwiec authored Sep 4, 2019
2 parents d6035ac + 1560196 commit db77477
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions content/techniques/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,39 @@ export class PhotoService {

> warning **Notice** Don't forget to import the `PhotoModule` into the root `AppModule`.
If you want to use the repository outside of the module which imports `TypeOrmModule.forFeature`, you'll need to re-export the providers generated by it.
You can do this by exporting the whole module, like this:

```typescript
@@filename(photo.module)
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Photo } from './photo.entity';

@Module({
imports: [TypeOrmModule.forFeature([Photo])],
exports: [TypeOrmModule]
})
export class PhotoModule {}
```

Now if we import `PhotoModule` in `PhotoHttpModule`, we can use `@InjectRepository(Photo)` in the providers of the latter module.

```typescript
@@filename(photo-http.module)
import { Module } from '@nestjs/common';
import { PhotoModule } from './photo.module';
import { PhotoService } from './photo.service';
import { PhotoController } from './photo.controller';

@Module({
imports: [PhotoModule],
providers: [PhotoService],
controllers: [PhotoController]
})
export class PhotoHttpModule {}
```

#### Multiple databases

Some projects require multiple database connections. This can also be achieved with this module. To work with multiple connections, first create the connections. In this case, connection naming becomes **mandatory**.
Expand Down

0 comments on commit db77477

Please sign in to comment.