X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FMikroOrmStorage.ts;h=7269ce76dae82587822e38cfafd485e3aca03e64;hb=6c0215d2bf5a098aceed9e9d94d75d50ff2630db;hp=a1cc7c8db99c38e0b217fd8a66cedef99a1944d5;hpb=13a6f27c10768faa05acf33fd8e0637511d49e3e;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index a1cc7c8d..7269ce76 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -3,9 +3,9 @@ import { MikroORM as MariaDbORM, type Options as MariaDbOptions } from '@mikro-orm/mariadb' import { MikroORM as SqliteORM, type Options as SqliteOptions } from '@mikro-orm/sqlite' -import { Storage } from './Storage.js' import { type PerformanceRecord, type Statistics, StorageType } from '../../types/index.js' import { Constants } from '../../utils/index.js' +import { Storage } from './Storage.js' export class MikroOrmStorage extends Storage { private readonly storageType: StorageType @@ -19,6 +19,7 @@ export class MikroOrmStorage extends Storage { public async storePerformanceStatistics (performanceStatistics: Statistics): Promise { try { + this.setPerformanceStatistics(performanceStatistics) await this.orm?.em.upsert({ ...performanceStatistics, statisticsData: Array.from(performanceStatistics.statisticsData, ([name, value]) => ({ @@ -27,7 +28,11 @@ export class MikroOrmStorage extends Storage { })) } satisfies PerformanceRecord) } catch (error) { - this.handleDBError(this.storageType, error as Error, Constants.PERFORMANCE_RECORDS_TABLE) + this.handleDBStorageError( + this.storageType, + error as Error, + Constants.PERFORMANCE_RECORDS_TABLE + ) } } @@ -45,18 +50,19 @@ export class MikroOrmStorage extends Storage { } } } catch (error) { - this.handleDBError(this.storageType, error as Error) + this.handleDBStorageError(this.storageType, error as Error) } } public async close (): Promise { + this.clearPerformanceStatistics() try { if (this.orm != null) { await this.orm.close() delete this.orm } } catch (error) { - this.handleDBError(this.storageType, error as Error) + this.handleDBStorageError(this.storageType, error as Error) } }