我试图计算 golangapi 服务器发出请求时对数据库运行的查询的数量,这是为了在我们的API中优化+查找瓶颈。
这有个可参考的例子:https://stackoverflow.com/questions/19556139/get-sql-query-count-during-a-django-shell-session
你知道在 Golang 是否有一个简单的方法可以做到这一点吗?
我试图计算 golangapi 服务器发出请求时对数据库运行的查询的数量,这是为了在我们的API中优化+查找瓶颈。
这有个可参考的例子:https://stackoverflow.com/questions/19556139/get-sql-query-count-during-a-django-shell-session
你知道在 Golang 是否有一个简单的方法可以做到这一点吗?
No easy solution that I'm aware of.
You could wrap your db in your own struct, and then implement Exec() or whichever function you use directly on that struct. Your function would just call the database one, and count it however you see fit.
A similar example, but with a logger, can be found here: How to log queries to database drivers?