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