I'm using typeorm and I want to create a generic repository:
import "reflect-metadata";
import { DBManager } from './db-manager';
import { Photo } from './entities/Photo';
import { createConnection, Connection } from "typeorm";
class GenericRepository<T> {
private connection: DBManager;
constructor(connection: DBManager) {
this.connection = connection;
}
public list(): T[] {
let result: T[] = [];
this.connection.connect().then(async connection => {
result = await <Promise<T[]>>(connection.entityManager.find(T));
});
return result;
}
}
let genericReposity = new GenericRepository<Photo>(new DBManager());
genericReposity.list();
This code of course doesn't woork and complains on find method that can not find name T
T should be my entity but I don't know how to achieve this