You can get the generated SQL from the query builder by calling getQuery()
or getQueryAndParameters()
.
If you just want the query you can use getQuery()
.getRepository(Customer)
.createQueryBuilder("customer")
.where("customer.id = :id", { id: 1 })
// .getQuery()
//GIVES THIS RESULT
// “SELECT `customer`.`id` AS `customer_id`, `customer`.`firstName` AS `customer_firstName`, `customer`.`lastName` AS `customer_lastName`, `customer`.`deletedAt` AS `customer_deletedAt` FROM `customer` `customer` WHERE ( `customer`.`id` = :id ) AND ( `customer`.`deletedAt` IS NULL )”
//.getQueryAndParameters()
//GIVES THIS RESULT
// [
// “SELECT `customer`.`id` AS `customer_id`, `customer`.`firstName` AS `customer_firstName`, `customer`.`lastName` AS `customer_lastName`, `customer`.`deletedAt` AS `customer_deletedAt` FROM `customer` `customer` WHERE ( `customer`.`id` = ? ) AND ( `customer`.`deletedAt` IS NULL )”,
// [
// 1
// ]
// ]