Add MongDB support to storage for performance records.
[e-mobility-charging-stations-simulator.git] / src / utils / performance-storage / Storage.ts
index 890dce7a7c6687818faf9589f52c050b511d66a6..b8922375c39f3e983406aac5e0413968d31a3ec9 100644 (file)
@@ -1,14 +1,23 @@
+import { DBType } from '../../types/Storage';
 import Statistics from '../../types/Statistics';
 import { URL } from 'url';
+import logger from '../Logger';
 
 export abstract class Storage {
-  protected storageURI: URL;
-  protected logPrefix: string;
+  protected readonly storageURI: URL;
+  protected readonly logPrefix: string;
+  protected dbName: string;
 
   constructor(storageURI: string, logPrefix: string) {
     this.storageURI = new URL(storageURI);
     this.logPrefix = logPrefix;
   }
 
-  public abstract storePerformanceStatistics(performanceStatistics: Statistics): void;
+  protected handleDBError(DBEngine: DBType, error: Error, table?: string): void {
+    logger.error(`${this.logPrefix} ${DBEngine} error${table && ` in table or collection ${table}`} %j`, error);
+  }
+
+  public abstract open(): void | Promise<void>;
+  public abstract close(): void | Promise<void>;
+  public abstract storePerformanceStatistics(performanceStatistics: Statistics): void | Promise<void>;
 }