import config from 'config'; import { DataSource } from "typeorm"; import { ILogObj, Logger } from 'tslog'; import { Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift,HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup } from 'entity' export class OrmHelper { static DB: DataSource = null static setup() { const log: Logger = new Logger({ name: '[OrmHelper]', type: 'pretty' }); const engine: 'mysql' | 'postgres' = config.get("database.engine") OrmHelper.DB = new DataSource({ type: engine, host: config.get("database.host"), port: Number(config.get("database.port")), username: String(config.get("database.username")), password: String(config.get("database.password")), database: String(config.get("database.database")), synchronize: true, logging: config.get('database.logging'), entities: [Menu, Administrativu, Aldeia, District, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift,HospitalInformation, ItemGroup, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster], subscribers: [], migrations: [], }) OrmHelper.DB.initialize() .then(() => { // here you can start to work with your database }) .catch((error: any) => log.error(error)) } }