26 lines
607 B
TypeScript
26 lines
607 B
TypeScript
import { MikroORM } from '@mikro-orm/mysql'
|
|
|
|
import Logger, { LoggerType } from './logger'
|
|
import config from '../../mikro-orm.config'
|
|
|
|
class Database {
|
|
private static orm: MikroORM
|
|
private static logger = Logger.type(LoggerType.APP)
|
|
|
|
public static async initialize(): Promise<void> {
|
|
try {
|
|
this.orm = await MikroORM.init(config)
|
|
this.logger.info('Database connection initialized')
|
|
} catch (error) {
|
|
this.logger.error(`MikroORM connection failed: ${error}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
public static getORM(): MikroORM {
|
|
return this.orm
|
|
}
|
|
}
|
|
|
|
export default Database
|