OOP is my passion ( ͡° ͜ʖ ͡°)
This commit is contained in:
@ -6,8 +6,12 @@ import Logger, { LoggerType } from '#application/logger'
|
||||
|
||||
export abstract class BaseRepository {
|
||||
protected readonly logger = Logger.type(LoggerType.REPOSITORY)
|
||||
private entityManager?: EntityManager
|
||||
|
||||
protected get em(): EntityManager {
|
||||
return Database.getEntityManager()
|
||||
getEntityManager(): EntityManager {
|
||||
if (!this.entityManager) {
|
||||
this.entityManager = Database.getORM().em.fork()
|
||||
}
|
||||
return this.entityManager
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class Database {
|
||||
|
||||
public static async initialize(): Promise<void> {
|
||||
try {
|
||||
Database.orm = await MikroORM.init(config)
|
||||
this.orm = await MikroORM.init(config)
|
||||
this.logger.info('Database connection initialized')
|
||||
} catch (error) {
|
||||
this.logger.error(`MikroORM connection failed: ${error}`)
|
||||
@ -18,8 +18,8 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public static getEntityManager(): EntityManager {
|
||||
return Database.orm.em.fork()
|
||||
public static getORM(): MikroORM {
|
||||
return this.orm
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user