如何将一条SQL语句转换为TypeORM查询构建器? [英] How to translate an SQL statement to TypeORM query builder?
本文介绍了如何将一条SQL语句转换为TypeORM查询构建器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将下面的代码转换为TypeORM查询构建器? 我正在尝试遵循documentation。
this.repository.manager.query(`
SELECT item.name, item.id
FROM item_location
INNER JOIN item ON item.id = item_location.itemId
WHERE item_location.locationId = ${queryObject.filter};
`)
谢谢。
推荐答案
我想出来了。
await getManager()
.createQueryBuilder(Item, 'item')
.select(['item.id', 'item.name'])
.innerJoin('item.location', 'location')
.where('location.id = :id', { id: queryObject.filter });
这篇关于如何将一条SQL语句转换为TypeORM查询构建器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文