forked from noxious/server
Converted more procedural programming to OOP
This commit is contained in:
24
src/application/base/baseRepository.ts
Normal file
24
src/application/base/baseRepository.ts
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user