teableio/teable

View on GitHub
apps/nestjs-backend/src/global/knex/knex.module.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { DynamicModule } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { parseDsn } from '@teable/core';
import { KnexModule as BaseKnexModule } from 'nest-knexjs';

@Module({})
export class KnexModule {
  static register(): DynamicModule {
    return BaseKnexModule.forRootAsync(
      {
        inject: [ConfigService],
        useFactory: (config: ConfigService) => {
          const databaseUrl = config.getOrThrow<string>('PRISMA_DATABASE_URL');
          const { driver } = parseDsn(databaseUrl);

          return {
            config: {
              client: driver,
              useNullAsDefault: true,
            },
            name: 'CUSTOM_KNEX',
          };
        },
      },
      'CUSTOM_KNEX'
    );
  }
}