を使用して、一般的なリポジトリの作成:私は<a href="https://typeorm.github.io/index.html" rel="nofollow noreferrer">typeorm</a>を使用していると私は、一般的なリポジトリを作成したいtypeorm
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();
このコードofcurseがwoorkと名前T
を見つけることができませんfindメソッドに文句はありませんTは自分のエンティティでなければなりませんが、これを達成する方法がわかりません
何がうまくいかないのですか?実際の問題は何ですか? – toskv
私は私の例を編集しましたが、現在はもっと明確になっていると思っていますが、基本的には.find(T)は名前を付けられないと文句を言うT Tは写真でなければなりません。私の一般的な方法に – user4092086