我开发了typeorm
querybuilder
。为了进行调试,我想显示sql。
我测试了printSql()
方法。但没有显示任何SQL。
const Result = await this.attendanceRepository
.createQueryBuilder("attendance")
.innerJoin("attendance.child", "child")
.select(["attendance.childId","child.class","CONCAT(child.firstName, child.lastName)"])
.where("attendance.id= :id", { id: id})
.printSql()
.getOne()
console.log(Result);
它返回了。
Attendance { childId: 4, child: Child { class: 'S' } }
我想要的结果是获得SQL
有什么不对的地方吗?有什么好的方法来获取sql吗?
如果有人有意见,请告诉我。
谢谢
答案 0 :(得分:1)
.getQuery()
或.getSql()
const sql1 = await this.attendanceRepository
.createQueryBuilder("attendance")
.innerJoin("attendance.child", "child")
.select(["attendance.childId","child.class","CONCAT(child.firstName, child.lastName)"])
.where("attendance.id= :id", { id: id})
.getQuery();
console.log(sql1);
const sql2 = await this.attendanceRepository
.createQueryBuilder("attendance")
.innerJoin("attendance.child", "child")
.select(["attendance.childId","child.class","CONCAT(child.firstName, child.lastName)"])
.where("attendance.id= :id", { id: id})
.getSql();
console.log(sql2);