File: /var/dev/shahnamag/back-end/src/mysql-config.service.ts
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import { Verse } from './verse/entities/verse.entity';
import { VerseKeyword } from './verse/entities/verse-keyword.entity';
import { Keyword } from './keyword/entities/keyword.entity';
import { User } from './user/entities/user.entity';
import { Person } from './person/entities/person.entity';
import { VersePerson } from './verse/entities/verse-person.entity';
import { Section } from './section/entities/section.entity';
import { Predicate } from './predicate/entities/predicate.entity';
import { Triplet } from './triplet/entities/triplet.entity';
@Injectable()
export class MysqlConfigService implements TypeOrmOptionsFactory {
  constructor(private configService: ConfigService) {}
  createTypeOrmOptions(): TypeOrmModuleOptions {
    return {
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: this.configService.get<string>('mysql.user'),
      password: this.configService.get<string>('mysql.password'),
      database: this.configService.get<string>('mysql.db'),
      entities: [Keyword, Person, Verse, VerseKeyword, VersePerson, User, Section, Predicate, Triplet]
    };
  }
}