我正在使用TypeORM这样的查询。
userRepository
.createQueryBuilder("user")
.innerJoinAndSelect("user.profile")
.where("user.profile.reputation > :r" , {r:10})
.getMany();
这真的让我感到困扰,因为我不喜欢在代码中使用字符串作为标识符。例如,由于某种原因,我们决定将reputation
重命名为rate
,它将替换除这些查询之外的所有类型定义。
我还注意到QueryBuilder
接受字符串以外的其他参数
where(where: Brackets | string | ((qb: this) => string) | ObjectLiteral | ObjectLiteral[], parameters?: ObjectLiteral): this;
如何使用QueryBuilder定义类型化查询?