nestjs-knex icon indicating copy to clipboard operation
nestjs-knex copied to clipboard

handle connection state

Open ddtch opened this issue 1 year ago • 1 comments

Hello, I can't find how I can handle success or error connection to the database. AfterCreate method seems not working. Any ideas on how to do it? Basically, I want to have an opportunity to point callbacks on DB connected;

KnexModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        config: {
          log: new DbLogger(),
          debug: true,
          client: 'postgres',
          useNullAsDefault: true,
          connection: {
            host: configService.get('DB_HOST'),
            port: configService.get<number>('DB_PORT'),
            username: configService.get('DB_USERNAME'),
            password: configService.get('DB_PASSWORD'),
            database: configService.get('DB_NAME'),
          },
          afterCreate: (conn, error) => {
              // created with success or error
          },
        },
      }),
    }),

ddtch avatar Sep 01 '22 18:09 ddtch