如何将 sql 语句转换为 typeorm 查询生成器? [英] How to translate a sql statement to typeorm query builder?

查看:48
本文介绍了如何将 sql 语句转换为 typeorm 查询生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将下面的代码转换为 typeorm querybuilder?我正在尝试遵循 文档.

How would I convert the code below to typeorm querybuilder? I am trying to follow the 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆