X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FMikroOrmStorage.ts;h=e5b09b588b2a373ea14aa76854f9a3e5fc1df7f5;hb=42486f2357b011f9244c6b29f4e05185138ce8d1;hp=44be74918fa1d6ed9e50b69f10f6225a09a51b22;hpb=6c1761d470507ea23d186be61b94ca7375c5144a;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index 44be7491..e5b09b58 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -1,18 +1,27 @@ -// 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 { + Configuration, + Connection, + type IDatabaseDriver, + MikroORM, + type 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 type 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'; 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 +32,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); } @@ -66,12 +75,12 @@ export class MikroOrmStorage extends Storage { return { metadataProvider: TsMorphMetadataProvider, entities: [PerformanceRecord, PerformanceData], - type: this.storageType as MikroORMDBType, + type: this.storageType as MikroOrmDbType, clientUrl: this.getClientUrl(), }; } - private getClientUrl(): string { + private getClientUrl(): string | undefined { switch (this.storageType) { case StorageType.SQLITE: case StorageType.MARIA_DB: