Skip to content

Commit

Permalink
docs(sql) Mention exporting repository providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Starostin committed Aug 26, 2019
1 parent 98ead3d commit 1560196
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 @@ -180,6 +180,39 @@ export class PhotoService {

> warning **Notice** Do not forget to import the `PhotoModule` into the root `ApplicationModule`.
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 of your projects may require multiple database connections. Fortunately, this can also be achieved with this module. To work with multiple connections, the first thing to do is to create those connections. In this case, the connection naming becomes **mandatory**.
Expand Down

0 comments on commit 1560196

Please sign in to comment.