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