Add MongDB support to storage for performance records.
[e-mobility-charging-stations-simulator.git] / src / utils / performance-storage / Storage.ts
CommitLineData
2a370053 1import { DBType } from '../../types/Storage';
72f041bd
JB
2import Statistics from '../../types/Statistics';
3import { URL } from 'url';
2a370053 4import logger from '../Logger';
72f041bd
JB
5
6export abstract class Storage {
2a370053
JB
7 protected readonly storageURI: URL;
8 protected readonly logPrefix: string;
9 protected dbName: string;
72f041bd
JB
10
11 constructor(storageURI: string, logPrefix: string) {
12 this.storageURI = new URL(storageURI);
13 this.logPrefix = logPrefix;
14 }
15
2a370053
JB
16 protected handleDBError(DBEngine: DBType, error: Error, table?: string): void {
17 logger.error(`${this.logPrefix} ${DBEngine} error${table && ` in table or collection ${table}`} %j`, error);
18 }
19
20 public abstract open(): void | Promise<void>;
21 public abstract close(): void | Promise<void>;
22 public abstract storePerformanceStatistics(performanceStatistics: Statistics): void | Promise<void>;
72f041bd 23}