#Help for understand

20 messages · Page 1 of 1 (latest)

edgy crypt
#

To be honest, I've got no idea what he's talking about in that blog

tawny dagger
#

I think this Medium post might lead to more confusion than clarity. What exactly would you like to implement @nimble wind if we pretend you never read that article?

edgy crypt
nimble wind
edgy crypt
#

A provider is something you can inject. That's it. A service is a common type of provider.

#

A provider is made up of an injection token (usually this is the class reference, but it can be a string or a symbol), and a value to inject. Nest understands injection values to be either a direct value (useValue), a class reference (useClass, this is the default when you use an @Injectable() class), or a factory to build the injection value (useFactory).

nimble wind
somber lintel
# nimble wind That nice thx for explain, so if i would like to inject by db config in my prism...
nimble wind
# somber lintel https://docs.nestjs.com/fundamentals/custom-providers

I think i see thx a lot bro!

I do it like this that correct ?

import { Injectable } from '@nestjs/common';
import { PrismaClient } from '@prisma/client/scripts/default-index';
import { DatabaseConfigService } from '@/config/database/configuration.service';

@Injectable()
export class PrismaService extends PrismaClient {
  constructor(private configService: DatabaseConfigService) {
    super({
      datasources: {
        db: {
          url: configService.url,
        },
      },
    });
  }
}
somber lintel
nimble wind
#
@Injectable()
export class DatabaseConfigService {
  constructor(private configService: ConfigService) {}

  get user(): string {
    return this.configService.get<string>('database.user');
  }

  get password(): string {
    return this.configService.get<string>('database.password');
  }

  get port(): number {
    return this.configService.get<number>('database.port');
  }

  get url(): string {
    return this.configService.get<string>('database.url');
  }
}
somber lintel
#

then that's correct

nimble wind
somber lintel
nimble wind
#

Ok that nice thx a lot!

#

It's me again lol when i try to launch my app, it return this :

ERROR [ExceptionHandler] Nest can't resolve dependencies of the PrismaService (?). Please make sure that the argument DatabaseConfigService at index [0] is available in the PrismaModule context.

Potential solutions:
- Is PrismaModule a valid NestJS module?
- If DatabaseConfigService is a provider, is it part of the current PrismaModule?
- If DatabaseConfigService is exported from a separate @Module, is that module imported within PrismaModule?
  @Module({
    imports: [ /* the Module containing DatabaseConfigService */ ]
  })

I think it cause by my prisma.service.ts :

@Injectable()
export class PrismaService extends PrismaClient {
  constructor(private configService: DatabaseConfigService) {
    super({
      datasources: {
        db: {
          url: configService.url,
        },
      },
    });
  }
}

I search a solution but don't find it i try to import it in prisma module but nothing to do

somber lintel
#

you need to ensure that DatabaseConfigService do exists in the PrismaModule context

#

how? you do that by exporting DatabaseConfigService from the module that it was declared as a provider