如何将 sql 语句转换为 typeorm 查询生成器?

har*_*rry 7 sql database node.js typescript typeorm

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

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};
`)
Run Code Online (Sandbox Code Playgroud)

谢谢。

har*_*rry 4

我想到了。

await getManager()
    .createQueryBuilder(Item, 'item')
    .select(['item.id', 'item.name'])
    .innerJoin('item.location', 'location')
    .where('location.id = :id', { id: queryObject.filter });
Run Code Online (Sandbox Code Playgroud)

  • 有没有在线工具可以轻松转换? (3认同)
  • 什么是物品?我认为它是一个类,但仅此是行不通的。您可以更新项目类型定义吗? (2认同)