2025SELab2-project-Dwengo/backend/src/data/dwengo-entity-repository.ts
2025-03-06 13:37:42 +00:00

17 lines
553 B
TypeScript

import { EntityRepository, FilterQuery } from '@mikro-orm/core';
export abstract class DwengoEntityRepository<T extends object> extends EntityRepository<T> {
public async save(entity: T) {
const em = this.getEntityManager();
em.persist(entity);
await em.flush();
}
public async deleteWhere(query: FilterQuery<T>) {
const toDelete = await this.findOne(query);
const em = this.getEntityManager();
if (toDelete) {
em.remove(toDelete);
await em.flush();
}
}
}