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 {
public async storePerformanceStatistics (performanceStatistics: Statistics): Promise<void> {
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)
}
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, '')
}