Almost finalised refactoring
This commit is contained in:
@ -6,13 +6,11 @@ import config from '../../mikro-orm.config'
|
||||
|
||||
class Database {
|
||||
private static orm: MikroORM
|
||||
private static em: EntityManager
|
||||
private static logger = Logger.type(LoggerType.APP)
|
||||
|
||||
public static async initialize(): Promise<void> {
|
||||
try {
|
||||
Database.orm = await MikroORM.init(config)
|
||||
Database.em = Database.orm.em.fork()
|
||||
this.logger.info('Database connection initialized')
|
||||
} catch (error) {
|
||||
this.logger.error(`MikroORM connection failed: ${error}`)
|
||||
@ -20,18 +18,8 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public static getORM(): MikroORM {
|
||||
if (!Database.orm) {
|
||||
throw new Error('Database not initialized. Call Database.initialize() first.')
|
||||
}
|
||||
return Database.orm
|
||||
}
|
||||
|
||||
public static getEntityManager(): EntityManager {
|
||||
if (!Database.em) {
|
||||
throw new Error('Database not initialized. Call Database.initialize() first.')
|
||||
}
|
||||
return Database.em
|
||||
return Database.orm.em.fork()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user