improve logging printing in ORM sql
resolved #2098 resolved #2241
old:
new:
test code:
func TestA(t *testing.T) {
db.SetDebug(true)
var (
num = 5
wg = sync.WaitGroup{}
)
wg.Add(num)
for i := 0; i < num; i++ {
go func(i int) {
defer wg.Done()
sql := fmt.Sprintf("select sleep(%d)", i)
db.Raw(sql).All()
}(i)
}
wg.Wait()
}
这个日志就会出现2次打印了,有这折中的方案吗?
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
This log will be printed twice. Is there a compromise?
@houseme 暂时还没有想到,讨论一下
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@houseme I haven’t thought of it yet, let’s discuss it
@oldme-git @houseme 这两个issue的诉求是想要有一定的手段观测正在执行中的sql语句,不一定是要打印两条sql语句日志,这种方式有点丑,目前还没见到哪种语言的ORM会打印两条sql语句来满足这个诉求。我之前考虑过增加执行sql记录的方式,并提供查询当前正在执行sql的管理方法来满足。但这个诉求优先级并不高,所以一直没去做。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@oldme-git @houseme The appeal of these two issues' is to have a certain method to observe the sqlstatements being executed, not necessarily to print twosqlstatement logs. This method is a bit ugly. I haven't seen any language'sORMthat prints twosqlstatements to satisfy this request. I have previously considered adding a way to executesqlrecords and providing a management method to query the currently executingsql` to satisfy this need. But the priority of this request is not high, so it has never been done.