Skip to content
Advertisement

How to translate an SQL statement to TypeORM query builder?

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};
`)

Thanks.

Advertisement

Answer

I figured it out.

await getManager()
    .createQueryBuilder(Item, 'item')
    .select(['item.id', 'item.name'])
    .innerJoin('item.location', 'location')
    .where('location.id = :id', { id: queryObject.filter });
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement