本文介绍了如何在 typeorm querybuilder 中显示原始 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了 typeorm
querybuilder
.为了调试的目的,我想展示一下sql.
I developed typeorm
querybuilder
. For the aiming of debugging,I'd like to show sql.
我测试了 printSql()
方法.但它没有显示任何 SQL.
I tested printSql()
method. but it didn't show any 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?
Are there any wrong point ? Are there any good way to get sql ?
如果有人有意见,请告诉我.
If someone has opinion, please let me know.
谢谢
推荐答案
.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);
这篇关于如何在 typeorm querybuilder 中显示原始 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!