# Prisma

### Imports

{% tabs %}
{% tab title="Service" %}

```typescript
import { PrismaService } from 'niro-health';
```

{% endtab %}

{% tab title="Module" %}

```typescript
import { PrismaModule } from 'niro-health';
```

{% endtab %}

{% tab title="Interface" %}

```typescript
import type { IPrismaService } from 'niro-health';
```

{% endtab %}
{% endtabs %}

### Environment Variables

Do you create variables an `.env` file.

<table><thead><tr><th width="291">name</th><th width="460">description</th></tr></thead><tbody><tr><td><code>DATABASE_URL</code></td><td><code>Url of the database.</code></td></tr><tr><td><code>DB_PORT</code></td><td><code>Port of the database.</code></td></tr><tr><td><code>DB_USERNAME</code></td><td><code>Username of the database.</code></td></tr><tr><td><code>DB_PASSWORD</code></td><td><code>Password of the database.</code></td></tr><tr><td><code>DB_DATABASE_NAME</code></td><td><code>Name of the database.</code></td></tr></tbody></table>

Check the example file.

{% code title=".env" %}

```properties
DATABASE_URL=postgresql://postgres:postgres@localhost/project_development
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE_NAME=project_development
```

{% endcode %}

### Method of Use

To use this module, you need to inject it into the desired service.

{% code overflow="wrap" %}

```typescript
import { Module } from '@nestjs/common';
import { AppHostService, PrismaService } from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IAppHostService',
      useClass: AppHostService,
    },
    {
      provide: 'IPrismaService',
      useClass: PrismaService,
    },
  ],
})
export class AppModule {}
```

{% endcode %}

Injecting the module into our service.

```typescript
import { Inject, Injectable } from '@nestjs/common';
import type { IAppHostService, IPrismaService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IAppHostService')
    private readonly appHostService: IAppHostService,
    @Inject('IPrismaService')
    private readonly prismaService: IPrismaService,
  ) {}

  async enableShutdownHooks() {
    await this.prismaService.enableShutdownHooks(this.appHostService.app);
  }
}
```

Modifying our <mark style="color:blue;">**`main.ts`**</mark>

{% code title="main.ts" %}

```typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from '@/app.module';
import { Logger } from '@nestjs/common';
import { AppHostModule, AppHostService } from 'niro-health';
import { AppModule } from './app.module';
import { AppService } from './app.service';

(async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: new Logger('NestApplication', {
      timestamp: true,
    }),
    cors: true,
  });
  app.select(AppHostModule).get(AppHostService).setApp(app);
  app.select(AppModule).get(AppService).enableShutdownHooks();
})();
```

{% endcode %}

### With dependencies

You will need to inject the following interfaces.

<table><thead><tr><th width="308">Interface</th><th>Service</th></tr></thead><tbody><tr><td><code>AppHostService</code></td><td><a href="../app-host">Link to Service documentation</a></td></tr></tbody></table>

### Properties

### Methods

<table><thead><tr><th width="260.3333333333333">Method</th><th width="116" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>onModuleInit</code></td><td align="center"><code>public</code></td><td><code>This method is used to connect to the database.</code></td></tr><tr><td><code>enableShutdownHooks</code></td><td align="center"><code>public</code></td><td><code>This method is used to close the connection to the database.</code></td></tr></tbody></table>
