1
0
forked from noxious/server

Converted more procedural programming to OOP

This commit is contained in:
2024-12-26 23:34:25 +01:00
parent b7f448cb17
commit e571cf2230
46 changed files with 449 additions and 382 deletions

View File

@ -0,0 +1,24 @@
import { appLogger } from '../logger'
import { Database } from '../database'
import { EntityManager, MikroORM } from '@mikro-orm/core'
export abstract class BaseRepository {
protected orm!: MikroORM
protected em!: EntityManager
constructor() {
this.initializeORM().catch((error) => {
appLogger.error(`Failed to initialize Repository: ${error instanceof Error ? error.message : String(error)}`)
})
}
private async initializeORM() {
try {
this.orm = await Database.getInstance()
this.em = this.orm.em.fork()
} catch (error: any) {
appLogger.error(`Failed to initialize ORM: ${error instanceof Error ? error.message : String(error)}`)
throw error
}
}
}