Merge dependabot/npm_and_yarn/prettier-3.2.4 into combined-prs-branch
[e-mobility-charging-stations-simulator.git] / src / performance / storage / StorageFactory.ts
1 // Copyright Jerome Benoit. 2021-2024. All Rights Reserved.
2
3 import { JsonFileStorage } from './JsonFileStorage.js'
4 import { MikroOrmStorage } from './MikroOrmStorage.js'
5 import { MongoDBStorage } from './MongoDBStorage.js'
6 import type { Storage } from './Storage.js'
7 import { BaseError } from '../../exception/index.js'
8 import { StorageType } from '../../types/index.js'
9
10 // eslint-disable-next-line @typescript-eslint/no-extraneous-class
11 export class StorageFactory {
12 private constructor () {
13 // This is intentional
14 }
15
16 public static getStorage (
17 type: StorageType,
18 connectionUri: string,
19 logPrefix: string
20 ): Storage | undefined {
21 let storageInstance: Storage
22 switch (type) {
23 case StorageType.JSON_FILE:
24 storageInstance = new JsonFileStorage(connectionUri, logPrefix)
25 break
26 case StorageType.MONGO_DB:
27 storageInstance = new MongoDBStorage(connectionUri, logPrefix)
28 break
29 case StorageType.SQLITE:
30 case StorageType.MARIA_DB:
31 case StorageType.MYSQL:
32 storageInstance = new MikroOrmStorage(connectionUri, logPrefix, type)
33 break
34 default:
35 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
36 throw new BaseError(`${logPrefix} Unknown storage type: ${type}`)
37 }
38 return storageInstance
39 }
40 }