X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FMikroOrmStorage.ts;h=47823c8052d94800f779f85bfe2e182c12f62396;hb=6b635033ddf255392ded26fd03fe1f128b15ad69;hp=df96d6a6b078794f54101806caf30eb94fbe95e0;hpb=8114d10e3893e96bb725ce2fca9744429ee4b75b;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index df96d6a6..47823c80 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -1,18 +1,21 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core'; import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; -import { PerformanceData } from '../../types/orm/entities/PerformanceData'; -import { PerformanceRecord } from '../../types/orm/entities/PerformanceRecord'; -import Statistics from '../../types/Statistics'; -import { MikroORMDBType, StorageType } from '../../types/Storage'; -import Constants from '../../utils/Constants'; -import { Storage } from './Storage'; +import { + type MikroORMDBType, + PerformanceData, + PerformanceRecord, + type Statistics, + StorageType, +} from '../../types'; +import { Constants } from '../../utils'; +import { Storage } from '../internal'; export class MikroOrmStorage extends Storage { private storageType: StorageType; - private orm: MikroORM | null; + private orm!: MikroORM | null; constructor(storageUri: string, logPrefix: string, storageType: StorageType) { super(storageUri, logPrefix); @@ -23,7 +26,7 @@ export class MikroOrmStorage extends Storage { public async storePerformanceStatistics(performanceStatistics: Statistics): Promise { try { const performanceRecord = new PerformanceRecord(); - await this.orm.em.persistAndFlush(performanceRecord); + await this.orm?.em.persistAndFlush(performanceRecord); } catch (error) { this.handleDBError(this.storageType, error as Error, Constants.PERFORMANCE_RECORDS_TABLE); } @@ -71,7 +74,7 @@ export class MikroOrmStorage extends Storage { }; } - private getClientUrl(): string { + private getClientUrl(): string | undefined { switch (this.storageType) { case StorageType.SQLITE: case StorageType.MARIA_DB: