X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FMikroOrmStorage.ts;h=9746c6bd5f5a09b439129338fc1dde2a1a82a013;hb=789007bd09242370a9d3502da967deb414886504;hp=d5e25bb2c6e7e205a98963bd3bd97195d7dc73cb;hpb=4ccf551d961ef001acef6fafe1165ad9b6dac4e3;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index d5e25bb2..9746c6bd 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -4,7 +4,7 @@ import { MikroORM as MariaDbORM, type Options as MariaDbOptions } from '@mikro-o import { MikroORM as SqliteORM, type Options as SqliteOptions } from '@mikro-orm/sqlite' import { Storage } from './Storage.js' -import { type Statistics, StorageType } from '../../types/index.js' +import { type PerformanceRecord, type Statistics, StorageType } from '../../types/index.js' import { Constants } from '../../utils/index.js' export class MikroOrmStorage extends Storage { @@ -19,8 +19,13 @@ export class MikroOrmStorage extends Storage { public async storePerformanceStatistics (performanceStatistics: Statistics): Promise { try { - // TODO: build PerformanceRecord entity - await this.orm?.em.persistAndFlush({}) + await this.orm?.em.persistAndFlush({ + ...performanceStatistics, + statisticsData: Array.from(performanceStatistics.statisticsData, ([name, value]) => ({ + name, + ...value + })) + } satisfies PerformanceRecord) } catch (error) { this.handleDBError(this.storageType, error as Error, Constants.PERFORMANCE_RECORDS_TABLE) } @@ -57,7 +62,7 @@ export class MikroOrmStorage extends Storage { private getDBName (): string { if (this.storageType === StorageType.SQLITE) { - return `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db` + return `${Constants.DEFAULT_PERFORMANCE_DIRECTORY}/${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db` } return this.storageUri.pathname.replace(/(?:^\/)|(?:\/$)/g, '') }