fix: various fixes to files handling and their content caching
[e-mobility-charging-stations-simulator.git] / src / performance / storage / StorageFactory.ts
1 // Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
2
3 import { JsonFileStorage } from './JsonFileStorage';
4 import { MikroOrmStorage } from './MikroOrmStorage';
5 import { MongoDBStorage } from './MongoDBStorage';
6 import type { Storage } from './Storage';
7 import { BaseError } from '../../exception';
8 import { StorageType } from '../../types';
9
10 export class StorageFactory {
11 private constructor() {
12 // This is intentional
13 }
14
15 public static getStorage(type: StorageType, connectionUri: string, logPrefix: string): Storage {
16 let storageInstance: Storage | null = null;
17 switch (type) {
18 case StorageType.JSON_FILE:
19 storageInstance = new JsonFileStorage(connectionUri, logPrefix);
20 break;
21 case StorageType.MONGO_DB:
22 storageInstance = new MongoDBStorage(connectionUri, logPrefix);
23 break;
24 // case StorageType.MYSQL:
25 // case StorageType.MARIA_DB:
26 // case StorageType.SQLITE:
27 // storageInstance = new MikroOrmStorage(connectionUri, logPrefix, type);
28 // break;
29 default:
30 throw new BaseError(`${logPrefix} Unknown storage type: ${type}`);
31 }
32 return storageInstance;
33 }
34 }