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 Statistics, StorageType } from '../../types/index.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
public async storePerformanceStatistics (performanceStatistics: Statistics): Promise<void> {
try {
- // TODO: build PerformanceRecord entity
- await this.orm?.em.persistAndFlush({})
+ this.setPerformanceStatistics(performanceStatistics)
+ await this.orm?.em.upsert({
+ ...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)
}
}
public async close (): Promise<void> {
+ this.clearPerformanceStatistics()
try {
if (this.orm != null) {
await this.orm.close()
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, '')
}