typescript - 为什么在 TypeORM 中 where 和结合 Query Builder 不起作用?
问题描述
我正在使用 typeorm 的查询生成器。
它适用于我的where
功能,并且适用于该take
功能。它在哪里返回 5 个项目(这是正确的),第一个是3
返回 3 个项目。但它不适用于两者一起使用。然后它总是只返回一项。我究竟做错了什么?
public async search(first?: number): Promise<Item[]> {
const findConditions: FindConditions<Item> = {
deleted: IsNull(),
};
return this.itemRepository
.createQueryBuilder()
.select("item")
.from(Item, "item")
.where(findConditions)
.take(first)
.getMany();
}
解决方案
我的语法错误。因为我将查询生成器与我的itemRepository
一起使用,我不必使用select
andfrom
函数,因为这会创建错误的FROM
语句。
所以这有效:
public async search(first?: number): Promise<Item[]> {
const findConditions: FindConditions<Item> = {
deleted: IsNull(),
};
return this.itemRepository
.createQueryBuilder()
.where(findConditions)
.take(first)
.getMany();
}
推荐阅读
- vue.js - 如何配置 jest 和 babel 以使用 vue?
- javascript - window.getSelection().anchorNode.closest('[data-key]') 上的“TypeError:t.closest 不是函数”
- c++ - 尝试尊重二维向量中的元素时出错
- http - 请求参数/查询字符串中是否存在有序对?在 GET 请求中
- javascript - 当html代码中的文本元素出现时,如何在chrome控制台中启动一个函数?
- c++ - 从构造函数的参数中扣除模板 size_t
- javascript - 具有相同类的多个按钮的单击事件
- powershell - Moving files older than X days not working in Powershell
- ruby - 如何使用模块化 Sinatra APP 将数据存储到 Activerecord 中?
- office-js - 无法调试 Office javascript 加载项