forked from noxious/server
26 lines
716 B
TypeScript
26 lines
716 B
TypeScript
import { EntityManager, MikroORM } from '@mikro-orm/core'
|
|
|
|
import { Database } from '../database'
|
|
import { appLogger } from '../logger'
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|