【发布时间】:2018-08-30 15:35:55
【问题描述】:
在我的 NestJS 项目中,我有这个 TypeORM 查询:
const users = await this.usersRepository.find({
skip,
take,
order: sortingObject,
join: {
alias: 'user',
leftJoinAndSelect: {
country: 'user.country_id',
},
},
});
现在我只想返回名称中带有John 的用户。在 SQL 中,这将是一个 LIKE 查询 LIKE %John%。
在https://github.com/typeorm/typeorm/blob/master/docs/find-options.md 中没有关于通配符LIKE 查询的信息。
How to perform a like query Typeorm 给出了一个解决方案:
.where("user.firstName like :name", {name: '%' + firstName + '%' })
但是我无法使用skip 和take,这在使用where() 而不是find() 时可用。
对我如何使用 TypeORM QueryBuilder 实现这一点有任何想法吗?
【问题讨论】:
标签: nestjs typeorm typeorm-datamapper