OOP is my passion ( ͡° ͜ʖ ͡°)

This commit is contained in:
2025-01-04 18:35:53 +01:00
parent 0b4420f956
commit 067976c54a
46 changed files with 165 additions and 164 deletions

View File

@ -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
}
}

View File

@ -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
}
}