X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils%2Fperformance-storage%2FStorage.ts;fp=src%2Futils%2Fperformance-storage%2FStorage.ts;h=160e01d8bdc435adf68dbb782e22169a1f3676cc;hb=c27c3eeea356b0692bef2327bb59aa99f9cbad8d;hp=b8922375c39f3e983406aac5e0413968d31a3ec9;hpb=ffd71f2c31025fcec6d5a95e1fba5d32c6d28e5b;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/performance-storage/Storage.ts b/src/utils/performance-storage/Storage.ts index b8922375..160e01d8 100644 --- a/src/utils/performance-storage/Storage.ts +++ b/src/utils/performance-storage/Storage.ts @@ -1,6 +1,10 @@ -import { DBType } from '../../types/Storage'; +// Copyright Jerome Benoit. 2021. All Rights Reserved. + +import { DBType, StorageType } from '../../types/Storage'; + import Statistics from '../../types/Statistics'; import { URL } from 'url'; +import Utils from '../Utils'; import logger from '../Logger'; export abstract class Storage { @@ -13,8 +17,21 @@ export abstract class Storage { this.logPrefix = logPrefix; } - protected handleDBError(DBEngine: DBType, error: Error, table?: string): void { - logger.error(`${this.logPrefix} ${DBEngine} error${table && ` in table or collection ${table}`} %j`, error); + protected handleDBError(type: StorageType, error: Error, table?: string): void { + logger.error(`${this.logPrefix} ${this.getDBTypeFromStorageType(type)} error${(!Utils.isNullOrUndefined(table) || !table) && ` in table or collection '${table}'`} %j`, error); + } + + protected getDBTypeFromStorageType(type: StorageType): DBType { + switch (type) { + case StorageType.MARIA_DB: + return DBType.MARIA_DB; + case StorageType.MONGO_DB: + return DBType.MONGO_DB; + case StorageType.MYSQL: + return DBType.MYSQL; + case StorageType.SQLITE: + return DBType.SQLITE; + } } public abstract open(): void | Promise;