| 1 | import { DBType } from '../../types/Storage'; |
| 2 | import Statistics from '../../types/Statistics'; |
| 3 | import { URL } from 'url'; |
| 4 | import logger from '../Logger'; |
| 5 | |
| 6 | export abstract class Storage { |
| 7 | protected readonly storageURI: URL; |
| 8 | protected readonly logPrefix: string; |
| 9 | protected dbName: string; |
| 10 | |
| 11 | constructor(storageURI: string, logPrefix: string) { |
| 12 | this.storageURI = new URL(storageURI); |
| 13 | this.logPrefix = logPrefix; |
| 14 | } |
| 15 | |
| 16 | protected handleDBError(DBEngine: DBType, error: Error, table?: string): void { |
| 17 | logger.error(`${this.logPrefix} ${DBEngine} error${table && ` in table or collection ${table}`} %j`, error); |
| 18 | } |
| 19 | |
| 20 | public abstract open(): void | Promise<void>; |
| 21 | public abstract close(): void | Promise<void>; |
| 22 | public abstract storePerformanceStatistics(performanceStatistics: Statistics): void | Promise<void>; |
| 23 | } |