fix: fix performance configuration change at runtime
[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 3import { JsonFileStorage } from './JsonFileStorage';
e1d9a0f4 4// eslint-disable-next-line @typescript-eslint/no-unused-vars
c1565026
JB
5import { MikroOrmStorage } from './MikroOrmStorage';
6import { MongoDBStorage } from './MongoDBStorage';
7import type { Storage } from './Storage';
7b5dbe91 8import { BaseError } from '../../exception';
268a74bb 9import { StorageType } from '../../types';
72f041bd
JB
10
11export class StorageFactory {
6c3cfef8
JB
12 private constructor() {
13 // This is intentional
14 }
72f041bd 15
6d2b7d01
JB
16 public static getStorage(
17 type: StorageType,
18 connectionUri: string,
19 logPrefix: string,
20 ): Storage | undefined {
21 let storageInstance: Storage;
72f041bd
JB
22 switch (type) {
23 case StorageType.JSON_FILE:
100a5301 24 storageInstance = new JsonFileStorage(connectionUri, logPrefix);
72f041bd
JB
25 break;
26 case StorageType.MONGO_DB:
1f5df42a 27 storageInstance = new MongoDBStorage(connectionUri, logPrefix);
72f041bd 28 break;
a6b3c6c3
JB
29 // case StorageType.MYSQL:
30 // case StorageType.MARIA_DB:
31 // case StorageType.SQLITE:
7f61131f 32 // storageInstance = new MikroOrmStorage(connectionUri, logPrefix, type);
a6b3c6c3 33 // break;
72f041bd 34 default:
7b5dbe91 35 throw new BaseError(`${logPrefix} Unknown storage type: ${type}`);
72f041bd
JB
36 }
37 return storageInstance;
38 }
39}