【发布时间】:2021-08-05 16:59:57
【问题描述】:
我在我的应用程序中使用 Typeorm for SQL Server。当我通过像 connection.query(select * from user where id = 1) 这样的原生查询时,性能非常好,不到 0.5 秒。
如果我们使用 findone 或 QueryBuilder 方法,大约需要 5 秒才能得到响应。
在进一步调试中,我们发现像这样直接将值传递给查询,
return getConnection("vehicle").createQueryBuilder()
.select("vehicle")
.from(Vehicle, "vehicle")
.where("vehicle.id='" + id + "'").getOne();
比
快return getConnection("vehicle").createQueryBuilder()
.select("vehicle")
.from(Vehicle, "vehicle")
.where("vehicle.id =:id", {id:id}).getOne();
我们可以做任何优化来解决参数化查询的问题吗?
【问题讨论】:
-
还有什么问题?)
-
我们可以做任何优化来解决参数化查询的问题吗?
标签: sql node.js typescript typeorm typeorm-datamapper